how to create table with paging with jsf, icefaces, java and html


New to Java, JSF, Icefaces? Here is some links to start with:
Why and when use ICEFACES?
First steps with jsf and java
icefaces without icefaces

In this example, instead of 'ui:repeat' we will use custom 'iceext:loop' tag.
This tag add some functionality like paging, mod, index.
Getting started with custom loop component
how to create custom loop jsf component: source code and example
Example for custom loop jsf component with zebra style and index

We use simplest HTML tags, together with "loop" tag, which loops on 'tr' element. We use "loop" tag, which works like 'ui:repeat' but add more functionality like paging, 'index' variable, 'mod' variable, and more
Also, we use 'iceext:tr' tag. This tag render 'tr' but has possibility create action binding on click event, in this example to select row.
Pros: every programmer, even not-jsf, can understand it. CSS is transparent: what you see is what you get.
Customization is simple too.
Use you favorite HTML editor, or JSF editor together with CSS tools to customize every aspect of this table, its easy!
fragment from TableWithPaging.jspx
		<caption>table with paging</caption> 
		<iceext:loop id="tableWithTooManyRows" value="#{tableWithPagingBean.rows}" 
			var="row" rows="10"> 
			<iceext:tr action="#{}" 
				style="#{(row.selected)?'background-color: gray;' : ''}"> 
				<td><ice:outputText value="#{}" /></td> 
				<td><ice:outputText value="#{}" /></td> 

This is main entry point. Its referenced by 'tableWithPagingBean' from faces-config.xml
package com.gpost.jsfexamples.tableWithPaging;

import java.util.List;

import com.drytools.collections.selectable.SelectableArrayList;
import com.drytools.tables.rows.ISelectableTableRow;
import com.drytools.tables.rows.SelectableTableRow;

* Java class for example 'table with paging'
* referenced as 'tableWithPagingBean' from faces-config.xml, 
* used in 'TableWithPaging.jspx'
public class TableWithPagingBean{

	List<ISelectableTableRow<ManWithPhone>> rows;

	public List<ISelectableTableRow<ManWithPhone>> getRows() {
		if (rows == null) {
			rows = new SelectableArrayList<ISelectableTableRow<ManWithPhone>>();
			// create same sample data...
			rows.add(new SelectableTableRow<ManWithPhone>(new ManWithPhone("Gary", "1234-6767")));
			rows.add(new SelectableTableRow<ManWithPhone>(new ManWithPhone("Bob", "5678-4553")));
			rows.add(new SelectableTableRow<ManWithPhone>(new ManWithPhone("John", "5698-4333")));
			// create more data so we can see paging...
			for (int i = 0; i < 100; i++) {
				rows.add(new SelectableTableRow<ManWithPhone>(new ManWithPhone("name"+i, "111-222-"+i)));
		return rows;

} // end of class

This class defines data in row.
package com.gpost.jsfexamples.tableWithPaging;

public class ManWithPhone {
	public ManWithPhone(String name, String phone) {
		super(); = name; = phone;

	String name;
	String phone;

	public String getName() {
		return name;

	public void setName(String name) { = name;

	public String getPhone() {
		return phone;

	public void setPhone(String phone) { = phone;

part of faces-config.xml


As we saw in this example, you can create perfect table with paging using simple html/css, then add some binding to your java beans and you get very flexible, easily customizable data table without complexity of 'h:dataTable' component.

No comments:

Post a Comment