Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 479
BestPractices Avatar asked Apr 18 '12 15:04

BestPractices


1 Answers

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).

like image 138
BalusC Avatar answered Nov 11 '22 19:11

BalusC