Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding "html: reset " button

 
Praveen Teegala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I make reset button to remove displayed validation errors and clear the fields, at the same time.
Now, the reset button, seems to ONLY clear the fields,when there are no
errors displayed, but does not do anything, when errors are being displayed.
Any help..!
 
Junilu Lacar
Bartender
Pie
Posts: 7316
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The html:reset tag renders a <input type="reset"> tag. Reset does not necessarily clear the form field values. The behavior of this tag is to actually restore the values of form fields to what they had in the initial response. If your response came with non-blank field values, then those values will be restored when you click on the reset button. To see what I mean, try changing the value of a field when you get an error message. Then click on the "reset" button. The field you changed should be changed back to the "wrong" value, not cleared.
To get the behavior you want, you need a submit button, only you'd have the attribute value="Reset", i.e. you'd have something like
<html:submit property="action" value="Reset">
In your action class, you'd process the "Reset" request by clearing out the form field values. Note that you'd also have to skip over any validation code when the "Reset" request is submitted.
Another alternative is to use JavaScript to clear the form fields to avoid making a round-trip to the server just to clear fields (not sure if you can clear the error message thought) but I don't particularly like doing that. In practice, I just leave the error message up, let the user correct any errors and resubmit the form.
 
Praveen Teegala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu,
Your suggestion did help me, to think of a work around.
As you said, I did use a submit button to get the functionality I need.
I am checking the value of hidden variable in the FormBean for "Reset" in the validate method and clearing the fields and errors.
Thanks alot.
Praveen.
 
Monika Jindal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having similar problem and I can't make Reset button as submit. If u make more than one submit buttons on page, then first one in the list becomes default for all ENTER hits. In my case, 'Reset' followed by 'Search'. That would mean, user enters data, hits enter and rather than performing valid operation, form gets Reset.
So, is there any other way to handle it...
Thanks
 
Junilu Lacar
Bartender
Pie
Posts: 7316
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic