It happens that you want something to be re-rendered only if ajax-request is executed without errors. Or in other words – you want to be lazy if it possible and not perform “reRender” if you could. Just like that funny guy – he have to be lazy to be strong
For example you have a dialog which call some ajax-action and you want to re-render it only if ajaxrequest is executed without errors
if yo’ll put a plain it will always reRender the “list” – even if ajax request has errors.
<a4j:commandLink action="#{actionBean.action}" reRender="list" value="Run" onComplete="if (!hasAjaxErrors()){closeModalPanel();}"/>
the workaround could be moving the reRendering to a separate a4j:jsFunction call and call it only when you want it
<a4j:commandLink action="#{actionBean.action}" value="Run onComplete="if (!hasAjaxErrors()){closeModalPanel();onCompleteFunction()}"/> <a4j:jsFunction name="onCompleteFunction" reRender="list" ajaxSingle="true"/>
pretty easy and your “list” will be reRendered only after success call to the “#{actionBean.action}”
XHTML code to inject the error-severity in the input field “requestSeverity”
<a4j:outputPanel ajaxRendered="true" id="severityPanel"> <h:form prependId="false" style="display:none" > <h:inputHidden id="requestSeverity" value="#{facesContext.maximumSeverity.ordinal}"/> </h:form> </a4j:outputPanel>
Javascript function to check presence of errors (error-messages-severity)
function hasAjaxErrors() { var errorSeverityElement = document.getElementById("requestSeverity"); if (errorSeverityElement){ return errorSeverityElement.value >= 2; } return false; }
