Each Button creates an entry inside the Param-List as long as it's member of the form. So I simple applied a check for the presence of that entry to the "required" parameter:
<h:form id="form" prependId="true">
...
<p:inputText id="someId"
required="#{param['form:save']==null}" ... />
...
<p:commandButton id="save" value="Save" />
<p:commandButton id="submit" value="Submit" />
<p:commandButton id="cancel" value="Cancel" immediate="true" />
</h:form>
When I click "Submit" the param['form:save']
is NULL
, which then turns the expression to true
so the validation is executed.
When I click "Save" the param['form:save']
is NOT NULL
(but empty!), which resolves to false
so the validation is ignored. (Or let's say JSF thinks it is not a required field due to the expression beeing evaluated to false
)