PrimeFaces AjaxBehavior Example

AjaxBehavior is an extension to standard of f:ajax. As already mentioned at the JavaServer Faces 2 Tutorial, different components have used the f:ajax for ajaxifying the component’s behavior. If you’ve looked into section  JSF and AJAX in the JSF 2 tutorials post, you’ll find different components having attached f:ajax for ajaxiyfing purpose.

Typically, AjaxBehavior act as the same way that the f:ajax provides, in that it’s attached to the primefaces components to ajaxify. As you will find within primefaces components series, the events will be listed and clarified at the time which the component has coming into discussion.

In this tutorial, I will explain how to use AjaxBehavior class and its attributes for handling the AJAX request. This class will be used with the ajax tags in the primefaces component.

1. AjaxBehavior Info

Ajax Behavior General Information

2. AjaxBehavior Attributes

Ajax Behavior Attributes

3. Managed Bean

package net.javabeat.primefaces;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;

public class AjaxBehavior {
	private String message;

	public String getMessage() {
		return message;

	public void setMessage(String message) {
		this.message = message;

	public void listener(AjaxBehaviorEvent e){
  • Note listener defined method that accept AjaxBehaviorEvent as parameter

4. The View


<html xmlns=""
		<script name="jquery/jquery.js" library="primefaces"></script>
		<h:form prependId="false">
			<h1>JavaBeat Primefaces Example</h1>
			<h2>Primefaces AjaxBehavior - Sample</h2>
			<h:outputText value="Type a message: "/>
			#{' '}
			<p:inputText id="in" value="#{ajaxBehavior.message}">
				<p:ajax process="in" update="out" event="blur" listener="#{ajaxBehavior.listener}"></p:ajax>
			#{' '}
			<p:outputLabel id="out" value="#{ajaxBehavior.message}"/>
  • Primefaces JavaScript (jquery.js) library that used are defined within Primefaces JAR file.

5. PrimeFaces AjaxBehavior Example Demo

The below snapshots shows you the result of assuming use for primefaces input component either the result of the ajax behavior itself for blur client event or the listener that used for listening the ajax event.

Primefaces AjaxBehavior Example Demo

AjaxBehavior Input Listener

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!