aspose file tools*
The moose likes Struts and the fly likes Retaining Form Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retaining Form Values" Watch "Retaining Form Values" New topic
Author

Retaining Form Values

Clarence Dyho
Greenhorn

Joined: Sep 17, 2001
Posts: 23
Hello.

When I submit a form, my action class checks for business logic. If that logic fails, I populate an ActionErrors object and save it back to the request and then forward to the same form. The errors are displayed (using <html:errors/> but then all the form entries are reset.

Is there a setting/config that I need to set so that the form entries would not be reset? How do I retain the values enetered into the form without saving them to session? Thank you.
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Hello,

I think you should have variables in ActionForm with getter and setter methods . And declare this fields in .jsp as <html:hidden>

This way after submission , when it loads the page , it will retrieve data from these fields

For example: you have a variable cityName in PersonalProfileForm.java
In you PersonalProfileForm.jsp , you have <html:hidden property="cityName"/>

And when it comes to display the value of it , say
<bean:write name="PersonalProfileForm" property="cityName" />

and in your ActionForm i.e PersonalProfileForm.java define two methods

getCityName() and setCityName(string city)


I hope it helps...
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hi Clarence,
if your input is a textbox and using <html:text property="name">, its value is loaded from the form bean automatically when display the same page with error messages.
Sira Leonard
Greenhorn

Joined: Sep 15, 2009
Posts: 1
In your action class,
return like this

return mapping.getInputForward();

You don't need hidden fields for this to work.

In your action mapping be sure to include input="pathtojsp/name of your jsp.jsp"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retaining Form Values