Note that there are some explanatory texts on larger screens.

plurals
  1. POdatatable pagination when using viewscoped bean
    primarykey
    data
    text
    <p>I have been using <code>JSF 1.2</code> in my application. most of my application pages consists of <code>h:datatable</code>. I came across <a href="http://balusc.blogspot.sg/2006/06/using-datatables.html" rel="nofollow">this</a> wonderful article which explain everything about datatables. As shown in the above article, i implemented the datatable pagination by binding my table to <code>HtmlDataTable</code> and using a session scoped bean.</p> <p>Now i am moving to <code>JSF 2.0</code> version. I wanted to convert my <code>sessionscoped</code> beans to <code>viewscoped</code> as most of my application pages are independent from one another.</p> <p>i came across <a href="http://balusc.blogspot.sg/2010/06/benefits-and-pitfalls-of-viewscoped.html" rel="nofollow">this</a> article which explains about the <code>Viewscoped</code> beans. It tells that we cannot use <code>binding</code> attribute of the datatable. and also it uses the <code>Datamodel</code>.</p> <p>I am now struck on how to implement datatable pagination with the <code>Datamodel</code> and <code>viewscoped</code> bean.</p> <p>I am having the following methods for pagination</p> <pre><code>public String pageFirst() { dataTable.setFirst(0); return ""; } public String pagePrevious() { dataTable.setFirst(dataTable.getFirst() - dataTable.getRows()); return ""; } public String pageNext() { dataTable.setFirst(dataTable.getFirst() + dataTable.getRows()); return ""; } public String pageLast() { try { int count = dataTable.getRowCount(); int rows = dataTable.getRows(); LOGGER.info("rowcount:" + count); LOGGER.info("rows:" + rows); dataTable.setFirst(count - ((count % rows != 0) ? count % rows : rows)); }catch(ArithmeticException e){ LOGGER.info("no rows to display: ",e); } return ""; } </code></pre> <p>And in the view i am using them like this</p> <pre><code>&lt;h:commandButton value="#{msgs.footerbutton1}" action="#{bean.pageFirst}" disabled="#{bean.dataTable.first == 0}" /&gt; &lt;h:commandButton value="#{msgs.footerbutton2}" action="#{bean.pagePrevious}" disabled="#{bean.dataTable.first == 0}" /&gt; &lt;h:commandButton value="#{msgs.footerbutton3}" action="#{bean.pageNext}" disabled="#{bean.dataTable.first + bean.dataTable.rows &gt;= bean.dataTable.rowCount}" /&gt; &lt;h:commandButton value="#{msgs.footerbutton4}" action="#{bean.pageLast}" disabled="#{bean.dataTable.first + bean.dataTable.rows &gt;= bean.dataTable.rowCount}" /&gt; </code></pre> <p>Please help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload