10

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
d-man
  • 57,473
  • 85
  • 212
  • 296

1 Answers1

19

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.

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