BestPractices
BestPractices

Reputation: 12876

How wipe out p:message from p:dialog on close?

I have a JSF 2.0 page that uses Primefaces p:dialog component. The user can enter information in the dialog and click save/cancel. If they have a validation error, it is shown on the dialog. When they close or cancel the dialog, I want any p:message components to be "wiped out", i.e. so that if the user then opens p the dialog again, they wont see old validation messages.

Use case is: user opens dialog, doesnt fill all required fields, clicks Save, required field error messages are shown in the dialog. User clicks cancel which closes the dialog. User then clicks the button to open up the dialog again. I dont want them to see the previous validation messages (which currently they can).

Upvotes: 7

Views: 6598

Answers (1)

BalusC
BalusC

Reputation: 1108742

Ajax-update the dialog component before opening it.

E.g.

<p:commandButton ... update=":dialog" oncomplete="dialog.open()" />

It will not only clear messages, but also input field values (or at least preserve them with right defaults).

Upvotes: 8

Related Questions