Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing an object from jsp to a Controller as a parameter

 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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: 108
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic