14 Replies Latest reply on Nov 5, 2007 8:39 PM by louisthelizard

    rich:datascroller is jumping between selected page on page r

    mkuehle

      I have a strange behaviour when refreshing the page with -F5 or hitting next or previous datascroller button: sometimes the selected pages jumps randomly from one to another page (e.g. from 5 to 9 or 9 to 2)

      Test environment:
      Facelets 1.1.12,
      JSF RI 1.1 (same behaviour with MyFaces 1.1.5)
      RichFaces 3.1.0 (same behaviour with 3.1.1 latest snapshot)
      JDK: 1.5
      Server: Tomcat 5.5.23

      The example code is very simple:
      Backing Bean to generate list:

      import java.util.ArrayList;
      import java.util.List;
      
      public class ListTestBB {
      
       public List getTestList(){
       List l = new ArrayList();
       for (int i = 0; i < 40; i++) {
       l.add("tmp" + i);
       }
       return l;
       }
      }
      


      And output jsf (xhtml) page:
       <h:form id="helloForm">
       <rich:datascroller for="testListTable"/>
       <rich:dataTable id="testListTable"
       value="#{TestListBB.testList}"
       var="testEntry"
       volumns="1" columnsWidth="150"
       rows="4">
       <rich:column>#{testEntry}</rich:column>
       </rich:dataTable>
       </h:form>
      


      Faces config:
       <managed-bean>
       <managed-bean-name>TestListBB</managed-bean-name>
       <managed-bean-class>ListTestBB</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
      


      The normal behaviour for this litttle code snipped (datascroller and datatable) should be: after selecting e.g. page 10 and do perform a browser/page reload with -F5. The selected initial page should be the first one.
      But doing this several times the output is very strange. The selected page is jumping around.
      The same strange result is coming up when using next and previous buttons. The selected page is always a random one.

      Or the other scenario: After selecting wild some pages and hitting then the next or previous button the selected page is jumping around unpredictable.

      If you want you can download this sample in a .war and try it yourself. http://webthreads.de/FaceletsTest.war

      Or try it live online: http://www.webthreads.de/FaceletsTest/listTest.jsf
      Click randmonly on some pages: e.g. 5 then 9 then 3 then 7 and then hit F5 for refresh or hit the next/previous button to see the strange jumping around behaviour

      Does someone know the reason of thi behaviour or a solution to prevent this?

      Thank you very much!

        • 1. Re: rich:datascroller is jumping between selected page on pa

          Have a similar Problem with the same configuration, see http://jboss.com/index.html?module=bb&op=viewtopic&t=120099.
          Did you find a solution?

          • 2. Re: rich:datascroller is jumping between selected page on pa
            mkuehle

            It seems that with tomcat 6 and jsf ri 1.2 this behaviour doesn't occur.

            Really freaking...

            But unfortunately i need it with tomcat 5 and jsf 1.1 :(

            • 3. Re: rich:datascroller is jumping between selected page on pa

              For me its working with richfaces 3.0.1....

              • 4. Re: rich:datascroller is jumping between selected page on pa
                amitev

                There is a workaround for this using tomahawk's t:buffer. You buffer the dataTable and put it after the scroller. Here is a sample http://www.irian.at/myfaces/buffer.jsf

                • 5. Re: rich:datascroller is jumping between selected page on pa
                  mkuehle

                  This workaround sadly doesn't work for this special problem :(. I think this is a bug in RichFaces 3.1.0.

                  I deployed a new example on webthreads - first page explained (only rich:datascroller and rich:table) above and second one with t:buffer.

                  First example - plain richfaces components: http://webthreads.de/DataScrollerTest/datascrollerBug.jsf
                  Second with tomahawk t:buffer: http://webthreads.de/DataScrollerTest/tomahawkTest.jsf

                  You can also download the war with source files in it: http://webthreads.de/DataScrollerTest.war

                  The old link to war and url written in first post arn't available anymore.

                  • 6. Re: rich:datascroller is jumping between selected page on pa
                    mkuehle

                    Next try was with latest available RichFaces 3.0.1 and there is exactly the same behaviour: selecting randomly pages and after refreshing page with F5 one random selected page is selected and not the first one.

                    The big problem is that this random selected page will be also viewed if i load another jsf page and come back. So not only on refreshing this page - also when coming back from an other page this strange behaviour is coming up.

                    Maybe it is a general bug in datascroller component?

                    • 7. Re: rich:datascroller is jumping between selected page on pa

                      Hi Nec,
                      which version of Richfaces are you using exactly? I tried the latest official release (http://download.jboss.com/jboss-richfaces/jboss-richfaces-3.0.1-bin.zip and it worked for me...

                      • 8. Re: rich:datascroller is jumping between selected page on pa
                        mkuehle

                        Hi,

                        i tried exactly the same as you.

                        I took the same sources as used in the downloadable war file, removed richfaces3.1 jars and added ajax4jsf and richfaces 3.01. jars. And changed the namespace in xhtml pages, of course.

                        • 9. Re: rich:datascroller is jumping between selected page on pa
                          mkuehle

                          Maybe this behaviour has nothing to do directly with the datascroller component.

                          I debugged the datascroller and HtmlDataTable classes and sometime in the public void restoreState(FacesContext context, Object state) method the value "_first" is set to an old value which was set some requests before.

                          For example if i select first page 3 and than page 5. The first browser page reload (-F5) creates the datalist and datascroller with the first row 0 because it can't restore a state. (returns null from object array).
                          The second browser page reload restores the attribute _first to the last selected datascroller page or randomly to one further.

                          I can't explain this restoring behaviour - does someone else knows something about it?

                          • 10. Re: rich:datascroller is jumping between selected page on pa
                            ilya_shaikovsky

                            JSF 1.1 has some problems with state restoring as far as I remember.. :/ JSF 1.1_2 RI solves some of them but not all. Seems it something about JSF 1.1

                            • 11. Re: rich:datascroller is jumping between selected page on pa
                              mkuehle

                              Next post =)
                              I tested it with the latest available SUN RI 1.1_02 JSF and SUN 1.2 RI implementation and with this one the behaviour is a bit clearer to understand, i think. With Sun RI the datascroller jumps always (or most times) back to first page but in backend he knows the latest ajax state.

                              Try this on the new online example with JSF 1.1 RI: Initial loading of sample page. Klick to one page - e.g. page 5. After selected page 5 is viewed reload your browser window with F5 - the selected page should be the initial one: page 1 as expected.
                              As next select the previous or next button on datascroller component and you will see that the next selected page is either the next to page 5 (next button -> page 6) or the previous (previous button -> page 4).

                              I think, this is because with the next ajax request the last component state, stored on last ajax request, will be restored (which was page 5 on last ajax request).

                              Maybe the problem is that ajax4jsf viewhandler doesn't know or doesn't react right (e.g. reset the latest ajax component state) if a normal request comes in.


                              Online example Sun RI 1.1: http://www.webthreads.de/DatascrollerTestJsfRi/datascrollerBug.jsf

                              You can also download the war (includes source files) and try it yourself local.
                              http://www.webthreads.de/DatascrollerTestJsfRi.war

                              • 12. Re: rich:datascroller is jumping between selected page on pa
                                michaelgsearles

                                Hi All,

                                Test environment:
                                MyFaces 1.1.4
                                RichFaces 3.1.0
                                JDK: 1.5
                                Server: Tomcat 5.0.28

                                I am having a very similar problem as described, but with one exception, I am not using Richfaces datascroller, instead, I am using the datascroller component from Tomahawk.

                                Once I drop the Richfaces 3.1.0 Jars into my project, it breaks my Tomahawk Datascroller component - the random jumping problem between pages when selecting the forward or back buttons.

                                Interestingly it does not happen with RichFaces 3.0.1

                                Mike.

                                • 13. Re: rich:datascroller is jumping between selected page on pa
                                  bfayle

                                  You can workaround this issue by creating an integer property on your backing bean and adding code in a restore view phase listener that restores the value in the datascroller component by calling the setPage() method. (Note - you need to cast your integer to string - see UIDataScroller)

                                  You will also need a scrollListener method that updates the integer property on your backing bean with the getPageIndex() value from the datascroller.

                                  There is still a very nasty bug with the dataScroller where it does not properly process the update model phase which prevents it from being used on editable datatables or forms where there are editable fields that should be re-rendered with different model values after a scroll event.

                                  I hope the RichFaces guys take notice and fix this - it's really quite nasty.

                                  • 14. Re: rich:datascroller is jumping between selected page on pa
                                    louisthelizard

                                    Here's what I did for a workaround:

                                    1) add an action listener to the dataSroller:
                                    <rich:datascroller align="center" for="prList" maxPages="20" actionListener="#{Bean.scrollAction}"/>

                                    2) Bind the datatable:

                                    <rich:dataTable width="300" id="prList" rows="12" columnClasses="col" value="#{Bean.requests}" var="tableData"
                                    binding="#{Bean.table}">

                                    3) In the Bean class:

                                    private UIDataTable table;
                                    private static final int last=17;
                                    private static final int length=12;
                                    private int page=0;
                                    .....

                                    public UIDataTable getTable() { return table; }
                                    public void setTable(UIDataTable table) { this.table = table; }

                                    public void scrollAction(ActionEvent event) {
                                    DataScrollerEvent dse = (DataScrollerEvent) event;
                                    String action = dse.getNewScrolVal();
                                    if ("first".equals(action)) {
                                    page=0;
                                    } else if ("last".equals(action)) {
                                    page=last-1;
                                    } else if ("fastrewind".equals(action)) {
                                    page--;
                                    } else if ("fastforward".equals(action)) {
                                    page++;
                                    } else {
                                    page = Integer.parseInt(action)-1;
                                    }
                                    }

                                    public List getTableData() {
                                    if (table != null) {
                                    table.setFirst(page*length);
                                    }
                                    return tableData;
                                    }