File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes validate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validate()" Watch "validate()" New topic


Julia Collins

Joined: Nov 08, 2002
Posts: 7
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
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
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:

"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The team, Newsletter 039.
Julia Collins

Joined: Nov 08, 2002
Posts: 7
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.
I agree. Here's the link:
subject: validate()
jQuery in Action, 3rd edition