Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.1.1.  < a4j:ajaxListener > available since 3.0.0

The <a4j:ajaxListener> component adds an action listener to a parent component and works like the <f:actionListener> or <f:valueChangeListener> JSF components but for the whole Ajax container.

The <a4j:ajaxListener> component adds an action listener to a parent component. That listener is invoked on each Ajax request during the "Render Response" JSF phase. In comparison with standard JSF <f:actionListener> and <f:valueChangeListener> components the invocation of the <a4j:ajaxListener> is not skipped in case when validation of "Update Model" fails. The <a4j:ajaxListener> is guarantied to be invoked for each Ajax response.

The "type" attribute defines the fully qualified Java class name for the listener. This Java class should implement org.ajax4jsf.event.AjaxListener interface which is base interface for all listeners, capable for receiving Ajax events. The object on which the Event initially occurred could be accessed using the java.util.EventObject.getSource() method.

The <a4j:ajaxListener> is not invoked for non-Ajax requests and when RichFaces works in the "Ajax Request generates Non-Ajax Response" mode, so <a4j:ajaxListener> invocation is a good indicator that Ajax Response is going to be processed. Let's check it in the following example.

Example:


...
<rich:messages/>
<h:form id="form">
    <a4j:commandLink value="Click to send Ajax request">
        <a4j:ajaxListener type="org.docs.richfaces.actionListenerBean"/>
    </a4j:commandLink>
</h:form>
...

Example:

...

public class ActionListenerBean implements org.ajax4jsf.event.AjaxListener {
    public void processAjax(AjaxEvent event) {
        FacesContext.getCurrentInstance().addMessage("form", new FacesMessage("Ajax request is sent"));
    }
}        
...

There is a result:


Table of <a4j:ajaxListener> attributes.


Visit AjaxListener page at RichFaces Livedemo for examples of component usage and their sources.

Check Sun JSF TLD documentation for more information on <f:valueChangeListener> tag.