wood burning stoves 2.0*
The moose likes Struts and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark ""reset " button not working properly" Watch ""reset " button not working properly" New topic
Author

"reset " button not working properly

kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
hi:
all, I use the validate() method of ActionForm to help me validate some inputs in the form in my JSP page, but I have encountered a strange error....

let us say if one of the input fields is invalid, then it will return to the original JSP page with the error msg(s), however, when that happens, my "Reset" button doesn't work properly, meaning, if i click the "reset" button , it won't clear out the fields for me.

But my "reset" button does clear out the fields when the user FIRST enters the JSP page,

so I thought it was rather strange, can sombody please lend me a hand?
many thanks....
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

reset doesn't clear the values, it turns them back into the defaults.

If you view the source of the page check out the value attributes of the textfields. Those are the values it will default to when reset is clicked.


A good workman is known by his tools.
kay lin
Ranch Hand

Joined: May 20, 2004
Posts: 132
so are you saying if i do the following


and when i click on the "reset" button, the text fields will be cleard? since value=""???

let me know please


many thanks..
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Yes. But I think that also means it will also override the prepopulation of values as well. (Everything will always be blank when you enter the page.)
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Originally posted by dog lin:
But my "reset" button does clear out the fields when the user FIRST enters the JSP page,

so I thought it was rather strange, can sombody please lend me a hand?
many thanks...


Marc is correct, the reset button does not clear the fields values, it restores them to the values that they had when the page was initially displayed. It just so happens that when you go to the page the first time, there are no values in the fields. In subsequent requests for the page where fields are prepopulated, reset simply restores the prepopulated values.

The processing of the regular "reset" button is entirely on the client side; no request is sent to the server. What I normally do to solve this problem is to use a Submit button instead with a value of "reset". Then I can make the receiving Action handle "reset" request by clearing the appropriate fields in the ActionForm.


Junilu - [How to Ask Questions] [How to Answer Questions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: "reset " button not working properly