JSF h:dataTable 分页

 

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());
    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值