Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a4j:commandLink oncomplete only when validation has succeed?

I am using JSF2, Richfaces4 and Spring. I have a command link. On execute I save records and on complete I execute search to display records like following code. Problem is that fireSearch() in oncomplete executes even if there is a validation error in form. I need to execute fireSearch() only when the record get saved successfully.

How can I the oncomplete only when validation has succeed?

<a4j:commandLink styleClass="button" action="#{myBean.save}" render="detail_form" execute="@form" oncomplete="fireSearch()">
<span> Save </span>
</a4j:commandLink>
like image 972
d-man Avatar asked May 28 '12 03:05

d-man


1 Answers

RichFaces supports request based EL evaluation in oncomplete attribute. So you should be able to print FacesContext#isValidationFailed() as if it's a JS condition.

For example,

oncomplete="if (#{!facesContext.validationFailed}) fireSearch()"

If validation has failed, this will ultimately result in

oncomplete="if (false) fireSearch()"

And thus the function won't be invoked.

like image 167
BalusC Avatar answered Sep 23 '22 01:09

BalusC