I have been using `JSF 1.2` in my application. most of my application pages consists of `h:datatable`. I came across [this](http://balusc.blogspot.sg/2006/06/using-datatables.html) wonderful article which explain everything about datatables. As shown in the above article, i implemented the datatable pagination by binding my table to `HtmlDataTable` and using a session scoped bean.

Now i am moving to `JSF 2.0` version. I wanted to convert my `sessionscoped` beans to `viewscoped` as most of my application pages are independent from one another.

i came across [this](http://balusc.blogspot.sg/2010/06/benefits-and-pitfalls-of-viewscoped.html) article which explains about the `Viewscoped` beans. It tells that we cannot use `binding` attribute of the datatable. and also it uses the `Datamodel`.

I am now struck on how to implement datatable pagination with the `Datamodel` and `viewscoped` bean.

I am having the following methods for pagination

```
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 "";
    }

```

And in the view i am using them like this

```
<h:commandButton value="#{msgs.footerbutton1}"
                 action="#{bean.pageFirst}"
                 disabled="#{bean.dataTable.first == 0}" />
<h:commandButton value="#{msgs.footerbutton2}"
             action="#{bean.pagePrevious}"
             disabled="#{bean.dataTable.first == 0}" />
<h:commandButton value="#{msgs.footerbutton3}"
             action="#{bean.pageNext}"
             disabled="#{bean.dataTable.first + bean.dataTable.rows
                             >= bean.dataTable.rowCount}" />
<h:commandButton value="#{msgs.footerbutton4}"
              action="#{bean.pageLast}"
              disabled="#{bean.dataTable.first + bean.dataTable.rows
                           >= bean.dataTable.rowCount}" />

```

Please help.