jsp:
* rows属性必须有
<h:dataTable value="#{deviceBugLabController.searchResults}" var="item" binding="#{deviceBugLabController.htmlDataTable}" rows="2">
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.fullcode}"/>
</f:facet>
<h:outputText value=" #{item.fullcode}"/>
</h:column>
...........
</h:dataTable>
<h:outputText value="总共:#{deviceBugLabController.itemCount}个 "/>
<h:outputText value="每页:#{deviceBugLabController.pageSize}个 "/>
<h:outputText value="共有:#{deviceBugLabController.pageCount}页 "/>
<h:outputText value="当前页:#{deviceBugLabController.pageIndex} "/>
<h:commandButton value="#{msgs.firstpage}" action="#{deviceBugLabController.firstAction}" disabled="#{deviceBugLabController.pageIndex == 1 || empty deviceBugLabController.searchResults}"/>
<h:commandButton value="#{msgs.prevpage}" action="#{deviceBugLabController.prevAction}" disabled="#{deviceBugLabController.pageIndex == 1 || empty deviceBugLabController.searchResults}"/>
<h:commandButton value="#{msgs.nextpage}" action="#{deviceBugLabController.nextAction}" disabled="#{deviceBugLabController.pageIndex == deviceBugLabController.pageCount || empty deviceBugLabController.searchResults}"/>
<h:commandButton value="#{msgs.lastpage}" action="#{deviceBugLabController.lastAction}" disabled="#{deviceBugLabController.pageIndex == deviceBugLabController.pageCount || empty deviceBugLabController.searchResults}"/>
java:
private HtmlDataTable htmlDataTable = new HtmlDataTable();
public int getItemCount() {
return htmlDataTable.getRowCount();
}
public int getPageCount() {
double pageDouble = (htmlDataTable.getRowCount() + htmlDataTable.getRows() - 1) / htmlDataTable.getRows();
int pageCount = (int) Math.ceil(pageDouble);
return pageCount;
}
public int getPageSize() {
return htmlDataTable.getRows();
}
public int getPageIndex() {
if(htmlDataTable.getFirst()==0){
return 1;
}
return htmlDataTable.getFirst()/htmlDataTable.getRows()+1;
}
public void nextAction() {
htmlDataTable.setFirst(htmlDataTable.getFirst() + htmlDataTable.getRows());
}
public void lastAction() {
htmlDataTable.setFirst(htmlDataTable.getFirst()+(htmlDataTable.getRowCount()/htmlDataTable.getRows())*htmlDataTable.getRows());
}
public void firstAction() {
htmlDataTable.setFirst(0);
}
public void prevAction() {
htmlDataTable.setFirst(htmlDataTable.getFirst() - htmlDataTable.getRows());
}