aspose file tools*
The moose likes Spring and the fly likes Passing an object from jsp to a Controller as a parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Passing an object from jsp to a Controller as a parameter" Watch "Passing an object from jsp to a Controller as a parameter" New topic
Author

Passing an object from jsp to a Controller as a parameter

laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
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
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing an object from jsp to a Controller as a parameter