in this post I will speak about Displaying JSF Data Scroller Pagination Information.
by default data table and data scroller JSF component have no direct way to display the pagination information
for example: displaying information about the current displayed records (31 - 40 From 96)
this can be done simply by doing the following steps:
- define abstract SortableList Class that have dataTable property as follows:
import javax.faces.event.ActionEvent; import org.apache.myfaces.component.html.ext.HtmlDataTable; /** * @author <a href="mailto:robinhoo.2006@gmail.com">Ali Abdel-Aziz</a> */ public abstract class SortableList extends BaseBean { /** the data table that will be used in binding to the JSF dataTable component. */ private HtmlDataTable dataTable; /** * reset Data Scroller to be at the first page. * @param e */ public void resetDataScroller(ActionEvent e) { if(dataTable != null) dataTable.setFirst(0); } /** * set the Html Data Table * @param dataTable */ public void setDataTable(HtmlDataTable dataTable) { this.dataTable = dataTable; } /** * get the Html Data Table. * @return dataTable */ public HtmlDataTable getDataTable() { return this.dataTable; } }
- any class that deals with data table should extend our defined SortableList as follows:
public class MangedBeanListBean extends SortableList
- inside the jsf page that you wanna display the pagination information (1 - 20 From 96) ad the following jsf panel grid:
add binding to our defined dataTable in <t:dataTable binding="#{managedBeanListBean.dataTable}" >
and
<t:panelGrid id="list_page_displaying_Count" columns="1" align="center"
style="width:12%" dir="RTL" >
<h:panelGroup style="align:ceneter;" styleClass="pagination">
<h:outputText value="#{mangedBeanBean.dataTable.first + 1} " />
<h:outputText value=" - " />
<h:outputText value="#{(mangedBeanListBean.rowCount < (sharedUtil.noOfTableRows + mangedBeanListBean.dataTable.first)) ?
mangedBeanListBean.rowCount : (sharedUtil.noOfTableRows + mangedBeanListBean.dataTable.first)} " />
<h:outputText value=" #{globalResource.from} " />
<h:outputText value="#{mangedBeanListBean.rowCount}" />
</h:panelGroup>
</t:panelGrid>
this will generate the following pagination information:


Recent comments
2 weeks 4 days ago
16 weeks 2 days ago
16 weeks 4 days ago
16 weeks 4 days ago
28 weeks 9 hours ago
32 weeks 1 day ago
33 weeks 2 days ago
1 year 6 days ago
1 year 6 days ago
1 year 4 weeks ago