0

I'm having a JSF form in which I have a textarea and multiple buttons. For the text area I'm doing validation using f:validator

<f:validator validatorId="myValidator" />
<a4j:support event="onsubmit" ajaxSingle="true" process="textarea1" />

The validator is working as expected. Now i have multiple submit buttons on the page i want the validation to happen on specific button only and validator should be ignored on the remaining buttons.

Is there anyway to restrict the validator on a specific submit button alone. Thanks.

rohit
  • 953
  • 5
  • 15
  • 31

2 Answers2

3

You can use the disabled attribute.

<f:validator validatorId="myValidator" disabled="#{empty param['formId:buttonId']}" />

Where formId is the ID of your <h:form> and the buttonId is the ID of the button which is supposed to be the only button to trigger validation.

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

I assume that you want to submit the textarea value to the server when clicking on other buttons too (so no point of playing with the process attribute)

How about adding immediate="true" to the other buttons ?

That way they will skip validation, while the submit button without immediate="true" will do the validation as expected

Or

There seems another workaround in this article JSF 2 - Conditionally Skip Validation

Something like

<h:commandButton action="#{bean.someMethod"} value="Submit2">
   <f:param name="skipValidation" value="true"/>
</h:commandButton>

and inside the validate method of the validator check for the skipValidation attirbute (look for further explanation in the article...)

Daniel
  • 36,833
  • 10
  • 119
  • 200