Hi Jorge,

open a JIRA-issue and attach a patch.

http://issues.apache.org/jira/TOMAHAWK

regards,

Martin



On 11/23/06, Jorge Vásquez <[EMAIL PROTECTED]> wrote:
Hi list I noticed that the error had to do with the fact that the
HtmlDataScroller class was using the same logic for keeping track of the
rowIndex.
This is the implementation of the broadcast method:
  /**
    * Invoke any action listeners attached to this class.
    * <p>
    * After listener invocation, the associated UIData's properties get
    * updated:
    * <ul>
    * <li>if the user selected an absolute page# then setFirst is called
with
    * uiData.getRows() * pageNumber.
    * <li>if the user selected the "first page" option then setFirst(0) is
called.
    * <li>if the user selected the "previous page" option then setFirst is
decremented
    * by uiData.getRows().
    * <li>if the user selected the "fast rewind" option then setFirst is
decremented
    * by uiData.getRows() * fastStep.
    * <li>next, fast-forward and last options have the obvious effect.
    * </ul>
    */
   public void broadcast(FacesEvent event) throws AbortProcessingException
   {
       super.broadcast(event);

       if (event instanceof ScrollerActionEvent)
       {
           ScrollerActionEvent scrollerEvent = (ScrollerActionEvent) event;

           broadcastToActionListener(scrollerEvent);

           // huh? getUIData never returns null.
           UIData uiData = getUIData();
           if (uiData == null)
           {
               return;
           }

           int pageindex = scrollerEvent.getPageIndex();
           if (pageindex == -1)
           {
               String facet = scrollerEvent.getScrollerfacet();
               if (FACET_FIRST.equals(facet))
               {
                   uiData.setFirst(0);
               }
               else if (FACET_PREVIOUS.equals(facet))
               {
                   int previous = uiData.getFirst() - uiData.getRows();
                   if (previous >= 0)
                       uiData.setFirst(previous);
               }
               else if (FACET_NEXT.equals(facet))
               {
                   int next = uiData.getFirst() + uiData.getRows();
                   if (next < uiData.getRowCount())
                       uiData.setFirst(next);
               }
               else if (FACET_FAST_FORWARD.equals(facet))
               {
                   int fastStep = getFastStep();
                   if (fastStep <= 0)
                       fastStep = 1;
                   int next = uiData.getFirst() + uiData.getRows() *
fastStep;
                   int rowcount = uiData.getRowCount();
                   if (next > rowcount)
                       next = (rowcount - 1) - ((rowcount - 1) %
uiData.getRows());
                   uiData.setFirst(next);
               }
               else if (FACET_FAST_REWIND.equals(facet))
               {
                   int fastStep = getFastStep();
                   if (fastStep <= 0)
                       fastStep = 1;
                   int previous = uiData.getFirst() - uiData.getRows() *
fastStep;
                   if (previous < 0)
                       previous = 0;
                   uiData.setFirst(previous);
               }
               else if (FACET_LAST.equals(facet))
               {
                   int rowcount = uiData.getRowCount();
                   int rows = uiData.getRows();
                   int delta = rowcount % rows;
                   int first = delta > 0 && delta < rows ? rowcount - delta
: rowcount - rows;
                   if (first >= 0)
                   {
                       uiData.setFirst(first);
                   }
                   else
                   {
                       uiData.setFirst(0);
                   }
               }
           }
           else
           {
               int pageCount = getPageCount();
               if (pageindex > pageCount)
               {
                   pageindex = pageCount;
               }
               else if (pageindex <= 0)
               {
                   pageindex = 1;
               }
               uiData.setFirst(uiData.getRows() * (pageindex - 1));
           }
       }
   }


So for now what I had to do was change my local implementation of this
component.  Something that works perfect and I guess has no mayor
implications for others is changing the position of the invocation of
method:  broadcastToActionListener(scrollerEvent);  This way if somebody
wants to make use of the ScrollerActionEvent to keep track of the firstRow
Index this method won't overwrite his/her work.  I moved it to the last line
of the:
if (event instanceof ScrollerActionEvent)...code portion and it works
perfect!!!!  I think this sounds like a reasonable change to the
dataScroller component.
Regards,
JV

p.d:  As I am not a member of the tomahawk developer crew what should I do
to suggest this change?


-----Mensaje original-----
De: Jorge Vásquez [mailto:[EMAIL PROTECTED]
Enviado el: miércoles, 22 de noviembre de 2006 18:29
Para: 'MyFaces Discussion'
Asunto: RE: Accessing datascroller paginator variables

Jeff,
During tests I found an issue.  It only happens with the first page and when
the user clicks on the next page.  What happens is that the next page that
appears is page 3 (page 2 is skipped).

I refined a bit my method letting it as follows: (I assume that the first
row has index 0):

       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() -
getLastPageRows());
                       } else if (clickedFacet.equals("fastr")) {
                               _rowIndex = (_rowIndex -
PAGINATOR_FAST_STEP*_rowsPerPage);
                               if (_rowIndex < 0) {
                                       _rowIndex = 0;
                               }
                       } else if (clickedFacet.equals("fastf")) {
                               _rowIndex = (_rowIndex +
PAGINATOR_FAST_STEP*_rowsPerPage);
                               if (_rowIndex > (_rowData.getRowCount() -
getLastPageRows())) {
                                       _rowIndex = (_rowData.getRowCount()
- getLastPageRows());
                               }
                       }
               } else {
               //Means a pageNumber was clicked
                       _rowIndex = (pageClicked*_rowsPerPage -
_rowsPerPage);
               }
       }

During debugging I check the value of rowIndex and it corresponds to the
first index of the second page but it skips that page and shows page 3.  Any
idea what is happening here?

Regards,
Jorge Vásquez


-----Mensaje original-----
De: Jeff Bischoff [mailto:[EMAIL PROTECTED]
Enviado el: miércoles, 22 de noviembre de 2006 10:22
Para: MyFaces Discussion
Asunto: Re: Accessing datascroller paginator variables

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
>>
>>
>
>
>
>




--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Reply via email to