I have a form with a validator on one field. I have two h:commandButtons: Ok and Cancel. When I input wrong data and click Cancel, I get a validation message. What must I do that validator don’t run when I click cancel?
I have a form with a validator on one field. I have two h:commandButton
Share
In case you aren’t using ajax, or are still on JSF 1.x, and you really need to invoke a business action in
cancel()method (i.e. just reloading the page is insufficient), then your best bet is to addimmediate="true"to the button. This way all input fields which don’t haveimmediate="true"will be skipped in processing.On JSF 2.x, much better is to submit the form by
<f:ajax>, which by default only processes@thisinstead of@form.If you want to navigate to another page here, add
?faces-redirect=trueto the outcome in thecancel()method.Or, if you actually don’t need to invoke any business action at all, then just use
<h:button>wherein you directly specify the (implicit) navigation case outcome.This will basically reload the page by a GET request. The
<h:button>doesn’t exist in JSF 1.x, but you can also just use plain HTML+JS for that.See also: