rich:自定义RichLazyDataModel上的dataScroller没有分页

时间:2015-06-24 10:23:02

标签: jsf jsf-2 pagination richfaces

我正在尝试使用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 class和RichLazyDataModel类,我在stackoverflow JSF, RichFaces, pagination中找到了一个问题

所以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;
    }

}

table.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>
                  .
                  .
                  .

1 个答案:

答案 0 :(得分:0)

RichLazyModelImpl.java中的一切都很好问题是我应该将包含 bootstrap 部分的<head>添加到xhml文件中,这在richFace网站的示例中没有提及现在一切正常。 Richface将负责分页。