aspose file tools*
The moose likes JSF and the fly likes  how to clear the values of components on validation errors in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark " how to clear the values of components on validation errors in JSF" Watch " how to clear the values of components on validation errors in JSF" New topic
Author

how to clear the values of components on validation errors in JSF

Sumeet Singh Aryan
Ranch Hand

Joined: Jul 30, 2008
Posts: 43
hi,
I have implemented a form in JSF with 10 components (combo box, text
boxes etc.). if any of the validation is failed in these components
then i want to clear the value of one particular component. e.g if
combo box is not selected then i want to clear one of the text boxes

Thanks in Advance


The woods are lovely, dark and deep, But I have promises to keep; And miles to go before I sleep, And miles to go before I sleep. - Robert Frost
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Run a PhaseListener which listens on beforephase of render response and sets the submitted values of all UIInput components to null.
Sumeet Singh Aryan
Ranch Hand

Joined: Jul 30, 2008
Posts: 43
But the code of phaseListener will execute on each and every request. i want to clear particular textbox on the single page not on all pages but at some validation error generated by another components
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just check if Iterator#hasNext() of FacesContext#getMessages() returns true and then change the component tree accordingly. If necessary also check the UIViewRoot#getViewId() if it matches the desired view.
Mansi Mishra
Ranch Hand

Joined: Dec 26, 2008
Posts: 50
Sumeet Aryan wrote:But the code of phaseListener will execute on each and every request. i want to clear particular textbox on the single page not on all pages but at some validation error generated by another components


You could try a javascript function


http://splashpress.blogspot.com
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
That does not clear the values in the managed bean.
Sumeet Singh Aryan
Ranch Hand

Joined: Jul 30, 2008
Posts: 43
Where to write the code of checking getMessages(). i can't write in submit button. my validations are occured after submission
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
As said, in the PhaseListener.
Sumeet Singh Aryan
Ranch Hand

Joined: Jul 30, 2008
Posts: 43
But how I came to know that the messages are coming from that particular page in which i want to clear the textbox
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
As said, if necessary check the view id.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to clear the values of components on validation errors in JSF