pagination in jsf

Posted by gurupriyan.e on Stack Overflow See other posts from Stack Overflow or by gurupriyan.e
Published on 2010-05-10T14:09:17Z Indexed on 2010/05/10 14:14 UTC
Read the original article Hit count: 353

Filed under:

I would like your comments and suggestion on this. I am doing the pagination for a page in jsf. The datatable is bound to a Backing Bean property through the "binding" attribute. I have 2 boolean variables to determine whether to render 'Prev' and 'Next' Button - which is displayed below the datatable. When either the 'Prev' or 'Next' button is clicked, In the backing bean I get the bound dataTable property and through which i get the "first" and "rows" attribute of the datatable and change accordingly. I display 5 rows in the page. Please comment and suggest if there any better ways. btw, I am not interested in any JSF Component libraries but stick to only core html render kit.

public String goNext()
{

    UIData htdbl = getBrowseResultsHTMLDataTable1();

    setShowPrev(true);
    //set Rows "0" or "5"
    if(getDisplayResults().size() - (htdbl.getFirst() +5)>5 )
    {
        htdbl.setRows(5);//display 5 rows
    }else if (getDisplayResults().size() - (htdbl.getFirst() +5)<=5) {
        htdbl.setRows(0);//display all rows (which are less than 5)
        setShowNext(false);
    }
    //set First
    htdbl.setFirst(htdbl.getFirst()+5);
    return "success";
}

public String goPrev()
{

    setShowNext(true);
    UIData htdbl = getBrowseResultsHTMLDataTable1();

    //set First
    htdbl.setFirst(htdbl.getFirst()-5);

    if(htdbl.getFirst()==0)
    {
        setShowPrev(false);
    }

    //set Rows - always display 5
    htdbl.setRows(5);//display 5 rows

    return "success";
}

© Stack Overflow or respective owner

Related posts about jsf