• 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)

Use a4j:status to display status of the request

July 18, 2008 //  by Krishna Srinivasan//  Leave a Comment

a4j:support and a4j:status

When there is a request to the server, the client have to wait untill he gets the response. It will be nice if you give status of the server request processing. use a4j:status tag in the RichFaces to implement this feature in your webpages. In this example this tag is used with a4j:support and showing the status message while user types in the text field.

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

This example also used some other useful attributes in the tag. Ti display the text message use starttext and stoptext. if you want to use image instaed of displaying text, the use
[code lang=”html”] <a4j:status>
<f:facet name="start">
<h:graphicImage value="process.gif"/>
</f:facet>
</a4j:status>

[/code].

Display the different styles using startStyle and stopstyle attributes.

richfaces.jsp

[code lang=”html”] <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<html>
<body>
<f:view>
<h:form id="jbForm1">
<h:outputText value="Employee id : "/>
<h:inputText value="#{richBean.empId}">
<a4j:support event="onkeyup" reRender="output" action="#{richBean.update}" />
</h:inputText>
</h:form>
<h:panelGrid id="output">
<h:column>
<a4j:status startText="Processing…." stopText="Processed." startStyle="color:green" stopStyle="color:red"/>
</h:column>
<h:column>
<h:outputText value="Updated Values : "/>
<h:outputText value="#{richBean.name}"/>
<h:outputText value="#{richBean.status}"/>
</h:column>
</h:panelGrid>

</f:view>
</body>
</html>
[/code]

JavaBeatRichfacesBean.java

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

import java.util.HashMap;
import java.util.Map;

public class JavaBeatRichfacesBean {
private String name;
private Integer empId;
private String status;

public Integer getEmpId() {
return empId;
}

public void setEmpId(Integer empId) {
this.empId = empId;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void update(){
Map<integer,String> map = new HashMap<integer,String>();
map.put(1, "Employee One");
map.put(2, "Employee Two");
map.put(3, "Employee Three");
map.put(4, "Employee Four");
this.name = map.get(this.empId);
if (this.name == null || this.name.trim().length() == 0)
{
this.status = "No Matching Found";
}
}

}
[/code]

faces-config.xml

[code lang=”xml”] <?xml version=’1.0′ encoding=’UTF-8′?>
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>richBean</managed-bean-name>
<managed-bean-class>javabeat.net.richfaces.JavaBeatRichfacesBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>[/code]

Category: JSFTag: Ajax4jsf

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « a4j:support – How to use action attribute?
Next Post: Use rich:datascroller for rich:dataTable pagination »

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