File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Regarding "html: reset " button" Watch "Regarding "html: reset " button" New topic
Author

Regarding "html: reset " button

Praveen Teegala
Greenhorn

Joined: Apr 03, 2004
Posts: 11
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..!


Praveen
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Praveen Teegala
Greenhorn

Joined: Apr 03, 2004
Posts: 11
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

Joined: May 04, 2004
Posts: 1
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

Joined: Feb 26, 2001
Posts: 4458
    
    6

Default submit buttons is kind of a thorny issue. See these:
http://lists.w3.org/Archives/Public/www-html/2001Sep/0033.html
http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding "html: reset " button