On a normal form submit to an action with validation, if validation fails, the request is forwarded to the input result and execute() is bypassed, yes. So, you have two options:

1) as Dave reiterated, you can put your form reset logic in validate(); have your validate method detect the when the reset submit button was pressed and, if so, clear the form.

2) use a 'cancel' button as the reset submit. A cancel button will (if you configure the action appropriately) bypass validation and call directly into your execute() method.

For my money, option 2 is the better approach, since cluttering validate() with non-validation concerns smells a bit... :p)

L.

Ashima Beri wrote:
Hi Laurie,
Thanks for the quick reply.
I want to reset the form fields after hitting a reset button.
When I thought of going about it through the Action class way and tried to
clear out my form fields , strangely i noticed that the Action class's
execute method is never called if there are still certain validations
failing. I read in struts flow explanation that Action class is only called if the
validations are passed through.
I dont know what other way to adopt.
Any suggestions?
Thanks
Ashima Beri


Laurie Harper wrote:
Ashima Beri wrote:
Hi,
I am trying to reset a validator form after the form is submitted and a
few
of the validations have failed.
Reset button used in the form clears out fields changed only since the
time
the form is loaded. That is it does just the client side reset. One way
that
i figured out was to submit the form back to the jsp so that the jsp
reloads
with all the form field reinitialized.
Is there some other method of clearing out the form fields after it has
failed the validations defined in validation.xml?
Thanks in advance for all the valuable suggestions!
Ashima Beri
Do you want to clear out the form fields before redisplaying the form after a validation error, or just allow the user to request a reset after the form is redisplayed?

Usually you would want to retain the data the user input after a validation failure, so they can correct mistakes without having to fill the entire form in again. If you really want to reset the form to its starting state before redisplaying, discarding the user's input, then you would need to do that in your validate() method (remember, if you don't already have a validate() method, that when you add one it needs to call super.validate() to trigger the XML-based validation).

If you just want to provide a button the user can click to reset the form, a 'submit' button and round trip through your action is the correct way to do so. As you've realized, a 'reset' button just tells the browser to restore the input values it received the last time the form was loaded.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to