jsfrichfacesajax4jsf

How to conditionally invoke a4j:commandButton oncomplete script depending on action outcome


I have a

<a4j:commandButton action="#{myBean.doCalculation}"
                   oncomplete="redirectBrowser()" />

However, if there is an error at myBean.doCalculation(), then oncomplete attribute is always invoked. How do I let it depend on result of action method?


Solution

  • You can check for errors in the oncomplete event and redirect when none are found. It can be done like this

    oncomplete="#{facesContext.maximumSeverity == null ? 'redirectBrowser()' : 'doSomethingElse()'}"