JavaBeat

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

Use rich:datascroller for rich:dataTable pagination

July 18, 2008 by Krishna Srinivasan Leave a Comment

rich:datascroller and rich:dataTable

rich:dataTable tag is the RichFaces version for datatable component which has few extra features on look and feel.One of the difficulty JSF developers is creating good pagination for the data dsiplayed using rich:datatable. To resole this problem, RichFaces tags library provides rich:datascroller component which can display the automatic paginations based on data populated using rich:dataTable.

also read:

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

This tips shows very basic working example using rich:datascroller.for attribute in the rich:datascroller is used for mapping to corresponding rich:dataTable. rows attribute in the dataTable used for displaying the number of rows in each page. There is many attributes in rich:datascroller to manipulate the look and the way it is diplaying data.

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>
<rich:datascroller for="sampleData" maxPages="10"/>
<rich:dataTable id="sampleData" value="#{richBean.employees}" var="loc" rows="10">
<rich:column>
<h:outputText value="#{loc.empId}"/>
</rich:column>
<rich:column>
<h:outputText value="#{loc.empName}"/>
</rich:column>
<rich:column>
<h:outputText value="#{loc.dept}"/>
</rich:column>
</rich:dataTable>
</h:form>
</f:view>
</body>
</html>[/code]

JavaBeatRichfacesBean.java

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

import java.util.ArrayList;
import java.util.List;

/**
* source : www.javabeat.net
*/
public class JavaBeatRichfacesBean {
private List<employee> employees;

public List<employee> getEmployees() {
this.employees = new ArrayList<employee>();
Employee employee = null;
for (int i = 0;i<50;i++)
{
employee = new Employee();
employee.setEmpId(String.valueOf(i));
employee.setEmpName("Name : " + i);
employee.setDept("JSF");
employees.add(employee);
}
return employees;
}

public void setEmployees(List<employee> employees) {
this.employees = employees;
}

}
[/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]

Filed Under: JSF Tagged With: Richfaces

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.

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.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved