自定义RichLazyDataModel上的rich:dataScroller不分页



我正在尝试使用JSF 2和RichFaces 4.3.7进行分页。我浏览了richface4中关于此链接中分页的示例:http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataScroller&sample=simpleScrolling&skin=blueSky

正如你所看到的,<rich:dataScroller for="table" maxPages="5" fastStep="3">没有增加任何值,我想知道它是如何控制下一页的数据库的?我实现了从数据库存储数据的类,并尝试处理分页。但当我点击下一页时,什么都不会发生。我想我错过了java类和RichLazyDataModel类中的一些东西,我在stackoverflow JSF、RichFaces、分页中的一个问题中找到了这些东西

因此RichLazyDataModelImpl扩展了该类任何帮助感谢

public class RichLazyDataModelImpl extends RichLazyDataModel<User> {
    int firstRow = 0;
    int numRows = 5;
    @Override
    public List<User> getDataList(int firstRow, int numRows) {
        return getDataList() ;
    }
    public List<User> getDataList() {
        try {
            Connection conn =  DriverManager.getConnection(configure.myUrl, "root",
                    "pass");
            String sql = "select * from messages order by id_messages"; // limit ? offset ? ";
            PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(sql);
            //stmt.setInt(2, new Integer(firstRow));
            //stmt.setInt(1, new Integer(numRows));
            ResultSet rs = stmt.executeQuery();

        List<User> result = new ArrayList<User>();
        while(rs.next()) {
            // read entry no. n
            User user = new User();
            String mobile =rs.getString("msg_msisdn");
            user.setMsg_mobile(mobile);
            String direction = rs.getString("msg_direction");
            user.setDirection(direction);
            String msg = rs.getString("msg_text");
            user.setMessage(msg);
            String status = rs.getString("msg_status");
            user.setMsg_status(status);
            Date time = rs.getDate("msg_time");
            user.setMsg_time((java.sql.Date) time);
            result.add(user);
            }
        return result;
    } catch (SQLException e) {

        e.printStackTrace();
    }
    return null;
    }
    @Override
    public Object getKey(User user) {
        // TODO Auto-generated method stub
        //return null;
        return user;
    }
    @Override
    public int getTotalCount() {
        String sql = " select count(*) as cnt from messages";
        PreparedStatement stmt;
        Integer result = 0;
        try {
            Connection conn =  DriverManager.getConnection(configure.myUrl, "pegah",
                    "pass");
            stmt = (PreparedStatement) conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();
            result = rs.getInt("cnt");
            rs.close();
            conn.close();
            System.out.println("The number of dataBase is "+result);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return result;
    }
    public void setCurrentPage(int page) {
        int row = (page-1) * numRows;
        firstRow = row;
    }
    public int getCurrentPage() {
        int page = firstRow / numRows;
        return page;
    }
}

表.xhtml

 <rich:dataScroller id="sc2" for="table" maxPages="3" fastStep="3" >
</rich:dataScroller>
 <rich:dataTable value="#{RichLazyDataModelImpl.getDataList()}" var="cate" id="table" rows="5">

                <rich:column >
                    <f:facet name="header">
                        <h:outputText value="Mobile " />
                    </f:facet>
                    <h:outputText value="#{cate.getMsg_mobile()}" />
                </rich:column>
                  .
                  .
                  .

RichLazyModelImpl.javaEverything are Fine问题是我应该将由bootstrap部分组成的<head>添加到xhml文件中,该文件在richFace网站上的示例中没有提到,现在一切都很好。Richface将负责分页。

相关内容

  • 没有找到相关文章

最新更新