• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Passing an object from jsp to a Controller as a parameter

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation where I have an object without a real identifier because the db result does not have a primary key. So, I need to be able to pass a selected object to display a couple of the details of the object. The details (i.e., text) of the object are all text, which is not a good idea to pass to the controller since there could be many caveats if passing text as a parameter, this is why I think passing the entire object instance into the method may be the best plan.

I thought I could use @ModelAttribute but I'm having difficulties because I have not used this before. Currently my object is being sent null.

This is an example of what I am doing.


My jsp follow:




The relevant part of my Controller...


Thanks for any help you can offer.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not much help on the second part. But if in the page it is all Strings, and the Controller takes other types, you do know that Spring MVC will do automatic conversions for you. String to int or Integer etc. And that you can also create custom Converters through the ConverterService if it is a more complex conversion.

Mark
 
laura mccord
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the parameter I have to send holds 1-2 sentences and sending text like that as a parameter is asking for trouble. Unfortunately, since the database table doesn't have a primary key I can't do a search based on a single identifier, which would have been so easy to just send the id and do a look up. So, I was hoping I could pass an entire Object instance from jsp to my Controller to call one of my getter methods() to retrieve the information.

Thanks,
Laura
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

laura mccord wrote:Well, the parameter I have to send holds 1-2 sentences and sending text like that as a parameter is asking for trouble. Unfortunately, since the database table doesn't have a primary key I can't do a search based on a single identifier, which would have been so easy to just send the id and do a look up. So, I was hoping I could pass an entire Object instance from jsp to my Controller to call one of my getter methods() to retrieve the information.

Thanks,
Laura



What do you mean sentences? Do you mean multiple fields/values.

Anyway, Spring and their form tags library does support backing a form with a domain object, and it magically can fill in the fields if you do a GET to get a blank domain object, or a pre-poulated one. Then on POST will send the Domain object populated to take as a parameter to a Controller method.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic