6 Replies Latest reply on Jul 21, 2011 11:11 PM by mchisty

    <rich:datascroller>: Reset of page index after re-rendering

    ma.aqcon

      Hi everyone,

      I have a question regarding <rich:datascroller>...

      I have the following use case:
      - User enters some filter criteria and clicks a button to display data in a dataTable
      - Data table is displayed, datascroller shows 10 pages
      - User selects e.g. page index 7 of 10
      - User changes the filter criteria and clicks the button again (New result has only e.g. 3 pages)
      - Data table is empty because the page index stil seems to be set to 7, the user has to select page 1/2/3 manually ...

      My question: Is there a way to set back the page index to 1?

      Thanks in advance&Regards
      Michael

        • 1. Re: <rich:datascroller>: Reset of page index after re-render
          sri_hari

          set the first attribute of the data table to 0

          • 2. Re: <rich:datascroller>: Reset of page index after re-render
            ma.aqcon

            Thanks for your response.

            I did a quick test without success but I will do some further investigation ...

            • 3. Re: <rich:datascroller>: Reset of page index after re-render
              daniel.soneira

              First - bind your datascroller into the backing bean.

              JSP:

              <rich:datascroller binding="${BackingBean.datascroller}"/>
              


              Then - in your search action you can invoke the method resetDatascroller described below.

              Here is the Backing bean:
              private UIDatascroller datascroller;
              
              public UIDatascroller getDatascroller() {
               return datascroller;
              }
              
              public void setDatascroller(UIDatascroller datascroller) {
               this.datascroller = datascroller;
              }
              
              private void resetDatascroller() {
               logger.debug("resetDatascroller");
               if (datascroller != null) {
               datascroller.setPage(UIDatascroller.FIRST_FACET_NAME);
               }
              }
              


              If one of the developers happens to read this - I don't know if this has been changed in 3.2.0 (I work with 3.1.5) - but could you please put a similar code snippet into the developer documentation for the datascroller. I guess this is a very common issue that almost everyone using a datascroller encounters very quickly.

              • 4. Re: <rich:datascroller>: Reset of page index after re-render
                ma.aqcon

                Thanks, Daniel! Your solution works fine for me!

                I have only two minor additions.
                JSP should be

                <rich:datascroller binding="#{BackingBean.datascroller}"/>
                

                This version of setPage is deprecated (probably in 3.2.0):
                 datascroller.setPage(UIDatascroller.FIRST_FACET_NAME);
                

                And is replaced by a version with an integer argument:
                 datascroller.setPage(1);
                


                • 5. Re: <rich:datascroller>: Reset of page index after re-render
                  ma.aqcon

                  This does not work with the latest 3.2.1GA anymore :-(

                  • 6. Re: <rich:datascroller>: Reset of page index after re-rendering
                    mchisty

                    This is a weird behaviour of RichFaces. However the following solution also works (you don't even have to bind with UIDatascroller) 

                     

                    Here is the java code snippet: WorkflowMaintain.java 

                     

                    private int page; 

                    public int getPage() {  return page; }       

                    public void setPage(int page) { this.page = page; } 

                    public void someActionMethod() { this.page=1; } 

                     

                    In page: mypage.xhtml 

                     

                    <rich:datascroller

                                                  for="workflow_item_datatable"

                                                  id="search_result_ds"

                                                  page="#{workflowMaintain.page}" />

                     

                    When re-rendering and calling the action method (someActionMethod), you just set the page variable to 1.  

                     

                     

                    Thanks,

                    .. Chisty