Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

skipping JSF validation for reset event

 
Vinodh Sa
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then fire an method on click of reset, there you just reinitialize the form value to an empty string
 
Vinodh Sa
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17622
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic