It allows Ajax capability to a non-Ajax component. The non-Ajax component must implement the ClientBehaviorHolder interface for all the event attributes that support behavior rendering.
We must use event attribute to the standard JSF event that triggers the behavior. If the event attribute is not defined, the behavior is triggered on the event that normally provides interaction behavior for the parent component.
RichFaces <a4j:ajax> Example
Here, in the following example, we are implementing <a4j:ajax> component. This example contains the following files.
JSF File
// ajax-event.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:a4j="http://richfaces.org/a4j"> <h:head> <title>a4j:ajax Tag</title> </h:head> <h:body> <h:form> <h:outputText value="Enter Text "></h:outputText> <h:inputText value="#{user.name}"> <a4j:ajax event="keyup" render="user-name"></a4j:ajax> </h:inputText> <br/> <br/> <h:outputText id="user-name" value=" #{user.name}"></h:outputText> </h:form> </h:body> </html>
Managed Bean
// User.java
import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped public class User { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
Next Topic:-Click Here