2

So i have this cancel button:

<p:commandButton id="cancelButton" value="Cancel" action="#{myBean.doOnCancel}" onclick="dialogWidget.hide();" />

The widget which the cancel button is on (<p:dialog>) has a date field. Everytime i open the dialog, enter some valid values and click cancel - myBean.doOnCancel gets executed and the dialog is hidden. Now everytime i open the dialog, enter a single invalid value, such as a single letter instead of date, i get a validation message saying the date format is bad, then click cancel - the dialog is hidden but the method defined in action (myBean.doOnCancel) is not executed. Any idea why?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
eight
  • 339
  • 1
  • 5
  • 16

1 Answers1

6

JSF will as per specification not invoke the action method when there's a validation error during processing the form submit. The <p:commandButton> processes by default the entire form as in <p:commandButton process="@form">. You want to limit it to the button itself only.

<p:commandButton ... process="@this" />

The dialog got successfully hidden, because it was performed entirely client side right before the form is submitted, independently from the result of the action method.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555