validate()

Julia Collins

Greenhorn

Posts: 7

posted 14 years ago

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

posted 14 years ago

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

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

Julia Collins

Greenhorn

Posts: 7

posted 14 years ago

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