• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

PrimeFaces AjaxBehavior Example

April 13, 2014 //  by Amr Mohammed//  Leave a Comment

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.

  • Read : PrimeFaces Tutorials

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

AjaxBehavior.java

[code lang=”java”] package net.javabeat.primefaces;

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

@ManagedBean
@SessionScoped
public class AjaxBehavior {
private String message;

public String getMessage() {
return message;
}

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

public void listener(AjaxBehaviorEvent e){
System.out.println(e);
}
}
[/code]

  • Note listener defined method that accept AjaxBehaviorEvent as parameter

4. The View

index.xhtml

[code lang=”xml”] <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<f:view>
<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:inputText>
#{‘ ‘}
<p:outputLabel id="out" value="#{ajaxBehavior.message}"/>
</h:form>
</f:view>
</html>
[/code]
  • 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

[wpdm_file id=62]

Category: JSFTag: PrimeFaces

About Amr Mohammed

Previous Post: « Primefaces AccordionPanel Client Side API Example
Next Post: Primefaces AjaxStatus Example »

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

np.zeros

A Complete Guide To NumPy Functions in Python For Beginners

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact