user652158
user652158

Reputation:

JSF2 BeanValidation reset values after failure

The modules of our web application shows a datatable in the center and the detail of the selected record on the right. Every time the user selects a record of the mastertable we update the detail page and show the details of the selected record. Now we have the following problem:

  1. User selects a record in the mastertable and data is displayed in detail area.
  2. User modifies the detail data and clicks on save.
  3. An validation(bean validation) error occurs and the user will see the error msg).
  4. Instead of correcting the wrong input the user selects another record of the mastertable.
  5. All fields that have no error state will be updated with the data of the new record. The fields that are wrong before shows the old data. The data of the old record stays until the user makes a page refresh.

Is there any way to solve this problem? I've seen a pe:resetInput component from Primefaces extensions but this component needs a UICommand component to work. I need a solution that works if the user selects another entry of the mastertable.

Upvotes: 2

Views: 2750

Answers (1)

BalusC
BalusC

Reputation: 1108632

You can use the ResetInputAjaxActionListener of OmniFaces for this. Apart from being registered as a <f:actionListener>, it can also be globally registered as a PhaseListener.

See also:


If you intend to take it in your own hands, then you basically need to write code yourself which does basically the following things:

  • During the invoke action phase, get to-be-rendered UIInput components which are not been executed/processed by the ajax request.
  • Invoke resetValue() method on them.

See also:

Upvotes: 2

Related Questions