Friday, August 02, 2013

JSF Tip of the Day: How do I reset input fields after a validation failure?

I was asked earlier today how to reset fields in a JSF application, if the validation fails. In his case, he had a Richfaces table which had values that were selectable. Once the value was selected, a pop-up box would appear in which you could change values. If the user input an incorrect value, the validation would fail and the box would remain. However, if he closed the box, or hit cancel... well it would retain the error values. If he selected another row from the table, it would contain the previous values.

This is a common issue, but he could not find a quick solution so I wrote one.

This function fetches the parent component which in his case was a form containing <h:inputText/> components, and then clears them. You may need to add some more code to do it recursively if the components are nested.

0 comments :

Popular Posts