This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Forward in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Forward in Spring" Watch "Forward in Spring" New topic
Author

Forward in Spring

Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

Hi,

I am trying to use Forward in Spring 3.0. My scenerio is I receive some data and put it in some Model attribute and forward to another page. Get few more data and try to put in same Model Object and send it to last page. Here I could see the data being retreived only from the last page and leaving rest of the Model fields are Null.

I assume, the ModelAttribute is re-instantiated somewhere in the middle which I fail to understand. Find below the Controller code





Please share your thoughts.


Ashwin Sridhar
SCJP | SCWCD | OCA
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

I tweaked a bit of my code in JSP and I was able to get the values in the final page. I created a hidden tag and the value seems to be retained. Otherwise it proceeds as if Null value is specified.

Can someone explain if my understanding is correct.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

Correct to get them back on the model attribute they must be bound to the object on the JSP. So the hidden tag is the correct approach.


[How To Ask Questions][Read before you PM me]
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

hi Bill, what if my form has more number of fields. creating hidden variables for all these may not be good. is there any way to retain it without hidden fields
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

If you are going to use a form backing bean which is essentially what this is then it has to be bound to something on the form (if the model attribute is request scoped). In the case it is not something you want shown on the form then hidden fields is typically what you use.

Alternatively you can have a look at the reference docs on the use of the @SessionAttributes annotation. You can also store things on the real HttpSession (you can pass HttpSession in as a method parameter) or you can pass values back an forth as @RequestParams.
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

Thanks Bill. Let me look at that.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Forward in Spring
 
Similar Threads
Spring MVC: Possible to submit a form without dependency on HttpSession
Problem with CheckBoxes
Spring MVC Request Mapping
JSF, strange form action generated
Problem with validation example