File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retaining Form Values" Watch "Retaining Form Values" New topic

Retaining Form Values

Clarence Dyho

Joined: Sep 17, 2001
Posts: 23

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

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
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 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

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:
subject: Retaining Form Values
It's not a secret anymore!