wood burning stoves 2.0*
The moose likes JSF and the fly likes skipping JSF validation for reset event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "skipping JSF validation for reset event" Watch "skipping JSF validation for reset event" New topic
Author

skipping JSF validation for reset event

Vinodh Sa
Ranch Hand

Joined: May 06, 2010
Posts: 55
hi all,

i need to skip jsf validation phase during the click of reset button in my jsp. Using "immediate=true", skips the validation well and good. But the problem here is, its not resetting the other values in the jsp.

Say, in the jsp there are totally 4 text fields for searching, now user has entered a special symbol in one of the text box and clicked on submit, now jsf validation runs and shows "Please enter a valid String".

At the same time if the user enters any special symbol and clicks on reset, now reset method is called, but the reset value of all the 4 text fields is not reflecting in the jsp(where i m setting the values back to null inside the reset() )

Any help would be appreciated.

Thanks.


Thanks, Vinodh
[Servlet tutorial]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I am not getting you. do you want the form to have existing value/old value back when a user click on reset? if yes then what is the point of resetting a form?
Vinodh Sa
Ranch Hand

Joined: May 06, 2010
Posts: 55
no Seetharaman... i want the values to be reset to null... but its still having the old value.... BTW i made the question a little bit confusing :-D
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

then fire an method on click of reset, there you just reinitialize the form value to an empty string
Vinodh Sa
Ranch Hand

Joined: May 06, 2010
Posts: 55
did the same seetharaman.... but its not working...

- if i dont add "immediate=true" for the reset button then, the jsf validation is getting fired.

- if i add "immediate=true", then the reset value i.e. null, which i did in the reset() is not reflecting in the jsp....
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

JSF is designed with the idea that the default handling of input data errors is to fail validation, which bypasses the backing bean updates and execution of the action method. re-rendering the page using the data values that were entered by the user. Normally, there will be error messages (validation messages) presented on the updated page (assuming you coded a place(s) to display them!). Thus, a screen print of the page shows what was mis-keyed and what the complaint was. Erasing the mis-keyed values could not only lead to confusion, but depending on the length and complexity of the input data could truly be annoying. More so, if you reset the entire form and not just the offending fields.

The JSF RESET control renders the low-level HTML RESET control. This object is wired directly to code in the client (browser) that replaces the input values in the form to the values they had when the page was displayed and is done without any interaction with the server whatsoever.

To achieve alternative behaviours, you'll need some help from JavaScript. You'd do this almost exactly the same way that non-JSF pages would. For example, you can attach a script to the SUBMIT (commandButton/commandLink) control's onclick function that validates locally and resets values. Generally, if you find a failed validation, the onclick code would return false to suppress the normal submit-to-server function.

At a more granular level, you can also attach javascript to the onblur functions of the individual input controls, That way, the minute you're done editing the control value, you'll get client-side validation.


Customer surveys are for companies who didn't pay proper attention to begin with.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Ah...yes I was wrong ... actually I never use required attribute.. most of the scenario I feel it is trouble than a worth .... apology for my wrong guidance....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: skipping JSF validation for reset event
 
Similar Threads
JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)
How restore disabled textbox values if there is any validation error in current page.
Struts 2 : Does s:reset is really capable for reset ?
Retaining List Values After Validating - Is there a way?
Struts 1.1 question (Might not be an easy one)