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

Retaining Form Values

 
Clarence Dyho
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic