Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate()

 
Julia Collins
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using struts and validating my form using the validate method in the form bean.
Whenever an error is found the error messages are correctly displayed on the form - but all the fields are emptied.
How do I make the fields redisplay the information entered so that the user does not need to reenter every time validation fails
Thanks
Julia
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have a form bean, so the hard part is already done. All you need to do is change your form in your jsp to use the struts-html taglib. For example, instead of using
<input type="text" ... >
you will use
<html:text ... >
Struts will figure out from your action which form to use, how they tie together, and which getters to use automagically. Pretty sweet, huh?
You should already have everything you need from your struts download/template/whatever, but
for reference on the HTML taglib, you can find it here: http://jakarta.apache.org/struts/struts-html.html
 
Julia Collins
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already am using <html:text> but have now discovered the problem. I was replacing the form bean with an empty one in my initial action.
Now I have added an if statement to check whether ActionErrors is empty or not.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic