Thanks JV,

If you have time, could you add a section about this approach to that wiki page? [1] I think this would be a great addition, as it certainly gives people more options.

We will need to come up with some intuitive section headings, separating the different approaches for clarity.

I think the most fundamental difference between our solutions is that mine revolves around the concept of marking or selecting a row. This marking is performed externally to the datascroller: through clicking a commandLink or executing some code in an action method. When the user returns from another page, they will be shown the datatable page which includes the row they marked. (whether or not it's the last one they viewed)

Your solution allows the current dataScroller page to be persisted much more directly. When the user returns from another page, they will be shown the datatable page which they last viewed.

I think certainly that some users will prefer one solution, while others will have a use case that requires the other. Having both on that wiki would be great. Of course, we need to format it well and explain it so that people know what the differences are.

[1] http://wiki.apache.org/myfaces/ManagingDataScrollerPage

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Jorge Vásquez wrote:
Hi Jeff,
I found another approach to maintain the page the user is at.  I am using
the actionListener attribute of the dataScroller.
In my xhtml page I have the following:

*************************XHTML CODE PORTION*****************************
                                <t:dataScroller id="scroll_1"
for="resultsData" fastStep="#{searchResultsBean.fastStep}"
                                        pageCountVar="pageCount"
pageIndexVar="pageIndex"
                                        styleClass="scroller"
paginator="true" paginatorMaxPages="#{searchResultsBean.paginatorMaxPages}"
                                        paginatorTableClass="paginator"
        
paginatorActiveColumnStyle="font-weight:bold;" immediate="false" rowsCountVar="totalRows"
        
firstRowIndexVar="currentPageFirstRow"
                                        lastRowIndexVar="currentPageLastRow"
                                        renderFacetsIfSinglePage="false"
actionListener="#{searchResultsBean.paginatorAction}">
                                        <h:outputFormat value="Rows {0}-{1}
of {2}" style="align:center">
                                                <f:param
name="mycurrentPageFirstRow" value="#{currentPageFirstRow}"/>
                                                <f:param
name="mycurrentPageLastRow" value="#{currentPageLastRow}"/>
                                                <f:param name="mytotalRows"
value="#{totalRows}"/>
                                        </h:outputFormat>
                                        <f:facet name="first">
                                                <t:graphicImage
url="/pages/images/arrow-first.gif" style="border:1px"
rendered="#{!searchResultsBean.firstPage}"/>
                                        </f:facet>
                                        <f:facet name="last">
                                                <t:graphicImage
url="/pages/images/arrow-last.gif" style="border:1px"
rendered="#{!searchResultsBean.lastPage}"/>
                                        </f:facet>
                                        <f:facet name="previous">
                                                <t:graphicImage
url="/pages/images/arrow-previous.gif" style="border:1px"
rendered="#{!searchResultsBean.firstPage}"/>
                                        </f:facet>
                                        <f:facet name="next">
                                                <t:graphicImage
url="/pages/images/arrow-next.gif" style="border:1px"
rendered="#{!searchResultsBean.lastPage}"/>
                                        </f:facet>
                                        <f:facet name="fastforward">
                                                <t:graphicImage
url="/pages/images/arrow-ff.gif" style="border:1px"
rendered="#{!searchResultsBean.lastPage}"/>
                                        </f:facet>
                                        <f:facet name="fastrewind">
                                                <t:graphicImage
url="/pages/images/arrow-fr.gif" style="border:1px"
rendered="#{!searchResultsBean.firstPage}"/>
                                        </f:facet>
</t:dataScroller>
****************************************************************************
In the managed bean I have the following relevant code:

**************************MANAGED BEAN CODE PORTION*************************
    private final static int DEFAULT_ROWS = 2;
    private final static int PAGINATOR_MAX_PAGES = 5;
    private final static int PAGINATOR_FAST_STEP = 5;
    private int rowIndex = 0;
    private int rowsPerPage = DEFAULT_ROWS;     

public void paginatorAction(ActionEvent event) {
                ScrollerActionEvent scrollerAction = (ScrollerActionEvent)
event;
                String clickedFacet = scrollerAction.getScrollerfacet();
                int pageClicked = scrollerAction.getPageIndex();
                //Means a facet was clicked
                if (clickedFacet != null) {
                        if (clickedFacet.equals("next")) {
                                rowIndex = rowIndex + rowsPerPage;
                        } else if (clickedFacet.equals("previous")) {
                                rowIndex = rowIndex - rowsPerPage;
                        } else if (clickedFacet.equals("first")) {
                                rowIndex = 0;
                        } else if (clickedFacet.equals("last")) {
                                rowIndex = _rowData.getRowCount() -
rowsPerPage;
                        } else if (clickedFacet.equals("fastrewind")) {
                                rowIndex = rowIndex -
PAGINATOR_FAST_STEP*rowsPerPage;
                                if (rowIndex < 0) {
                                        rowIndex = 0;
                                }
                        } else if (clickedFacet.equals("fastforward")) {
                                rowIndex = rowIndex +
PAGINATOR_FAST_STEP*rowsPerPage;
                                if (rowIndex >= _rowData.getRowCount()) {
                                        rowIndex = _rowData.getRowCount() -
rowsPerPage;
                                }
                        }
                } else {
                //Means a pageNumber was clicked
                        rowIndex = pageClicked*rowsPerPage - rowsPerPage;
                }
        }
        
    public int getRowIndex() {
        return rowIndex;
    }

    public int getRowsPerPage() {
        return SearchResultsBean.DEFAULT_ROWS;
    }
public boolean isFirstPage() {
        return (rowIndex < rowsPerPage);
    }

    public boolean isLastPage() {
        return (rowIndex >=  (_rowData.getRowCount() - rowsPerPage));
    }
public int getFastStep() {
        return SearchResultsBean.PAGINATOR_FAST_STEP;
    }
public int getPaginatorMaxPages() {
        return SearchResultsBean.PAGINATOR_MAX_PAGES;
    }

****************************************************************************

The most important method here is:  paginatorAction which captures all
scrollerActionEvents and according to the type of element clicked (either a
facet or a specific page) it displaces the rowIndex variable accordingly.
Also, I added conditional rendering to the facets based on whether the user
is at the first or last page.  If the user is at the first page there´s no
need to include first, previous and fastrewind facets and if the user is at
the last page there´s no need to include last, next and fastforward facets.

I haven´t included anything yet in the wiki but if you guys think this can
be helpful information to others then let me know and I´ll add it to the
wiki.

Regards,
JV

-----Mensaje original-----
De: Jorge Vásquez [mailto:[EMAIL PROTECTED] Enviado el: martes, 21 de noviembre de 2006 16:21
Para: 'MyFaces Discussion'
Asunto: RE: Accessing datascroller paginator variables

Thanks a lot Jeff.  Excelent document!!  My problem is that I am not using
command Links to view the details.  I have context menus for each row that
are built using the jscookMenu component.  I think that I should take a
closer look at the second approach that you suggest.
Thanks again,
JV
-----Mensaje original-----
De: Jeff Bischoff [mailto:[EMAIL PROTECTED] Enviado el: martes, 21 de noviembre de 2006 11:15
Para: MyFaces Discussion
Asunto: Re: Accessing datascroller paginator variables

Jorge,

I have contributed a wiki page [1] with my take on solving this scenario. Please let me know if anything is lacking, or feel free to edit the wiki yourself. :)

[1] http://wiki.apache.org/myfaces/ManagingDataScrollerPage

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Jorge Vásquez wrote:
Hi list,

I am using dataScroller for paginating a list.  I would like to have
access
to the current page in the bean in order to load it whenever a user
returns
to a list that was previously loaded.  My scenario is the user is loading
a
set of detail pages and when he/she comes back to the list it isn´t
loading
the page that he/she was at prior to going to the detail pages.  So I was
thinking if I can keep the current page in the bean but continue using
datascroller since I don´t want to reimplement all the pagination logic
that
this component already provides.

Thanks,

JV








Reply via email to