Is it possible to conditionally update JSF components only when validation succeeds?
I would like to be able to do something like
<p:commandLink process="@form" listener="#{foo}"
update="something somethingElse">
where “something” only gets updated if validation is successful.
Is there any way that can be done or is that just not supported in JSF?
I’ve been able to rig up kind of a hack with hidden commandLinks but not entirely satisfied:
<p:commandLink process="@form" listener="#{foo}"
update="somethingElse" oncomplete="if (!args.validationFailed) $("#link").click();">
<p:commandLink style="display:none" id="link"
update="something">
The
<h:message>(or PrimeFaces’ counterpart<p:message>) is intented for this. Or, in your case maybe better, the<h:messages>(or<p:messages>).with
Note that you’re as well supposed to use a normal
Validatorimplementation to perform the validation. If it throws aValidatorException, then the action won’t be invoked anyway. Doing validation inside action method is a smell.