【问题标题】:rich:dataScroller on custom RichLazyDataModel does not paginate自定义 RichLazyDataModel 上的 rich:dataScroller 不分页
【发布时间】:2015-09-10 12:11:54
【问题描述】:

我正在尝试使用 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>
                  .
                  .
                  .

【问题讨论】:

    标签: jsf jsf-2 pagination richfaces


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 2013-01-13
      相关资源
      最近更新 更多