12 Replies Latest reply on Mar 16, 2007 6:22 AM by Juan Ignacio Sánchez Lara

    Getting datascroller data

    Juan Ignacio Sánchez Lara Apprentice

      I'm a RichFaces newbie and I face a poor problem ;)

      I'm using dataTable and dataScroller. In my backing bean I have a HtmlDatascroller property. The problem is I don't know how can I get the position requested. When a user clicks one of the datascroller buttons I get the request at the server side, but I can't get which is the requested page of the table (the pressed button)?

      datascroller has one more issue: it just displays the buttons, not the actual position. Could it be related?

        • 1. Re: Getting datascroller data
          Adrian Mitev Master

          In the datascroller tag there is an attribute scrollerListener that allows you to bind the component with java method that will be invoked when scrolling occures. Example:

          <rich:datascroller scrollerListener="#{test.actionList}"

          java code:

          public void actionList(DataScrollerEvent event) {
          //do something here...
          }

          • 2. Re: Getting datascroller data
            Adrian Mitev Master

            I have a strange issue with the scroller. The scroll listener is not invoked the first time when scrolling occurs.

            • 3. Re: Getting datascroller data
              Juan Ignacio Sánchez Lara Apprentice

              It doesn't get triggered (the scrollerListener binding). Instead, the datatable value is. :-\

              • 4. Re: Getting datascroller data
                Adrian Mitev Master

                It's working. I've tested it.

                • 5. Re: Getting datascroller data
                  Juan Ignacio Sánchez Lara Apprentice

                  It is, sorry. Just a typo this time.

                  Now I can't get the index. It always return -1.

                  • 6. Re: Getting datascroller data
                    Juan Ignacio Sánchez Lara Apprentice

                    Well, not exactly a typo. If anybody anytime sees this, check if the action listener argument is ScrollerActionEvent. If it is, change it to ActionEvent ;)

                    • 7. Re: Getting datascroller data
                      Juan Ignacio Sánchez Lara Apprentice

                      Arg. It won't work. Now it doesn't even render scroller buttons. This is the code:

                      <rich:dataTable value="#{TareasPaginadorBean.tareas}"
                       var="tarea"
                       rowClasses="oddRow, evenRow"
                       headerClass="tableHeader"
                       id="tareasRC2"
                       first="#{TareasPaginadorBean.posicionActual}"
                       rows="#{TareasPaginadorBean.elementosPorPagina}">
                       <h:column>
                       <h:outputText value="#{tarea.id}"/>
                       </h:column>
                       <h:column>
                       <f:facet name="header">
                       <h:panelGroup>
                       <h:outputText value="Título"/>
                       [
                       <h:commandLink actionListener="#{TareasPaginadorBean.sortLinkAsc}" >
                       <f:attribute name="columna" value="titulo"/>
                       <h:outputText id="ascTitle" value="asc"/>
                       </h:commandLink>
                       <h:outputText value="|" />
                       <h:commandLink actionListener="#{TareasPaginadorBean.sortLinkDec}" >
                       <f:attribute name="columna" value="titulo"/>
                       <h:outputText id="decTitle" value="dec"/>
                       </h:commandLink>
                       ]
                       </h:panelGroup>
                       </f:facet>
                      
                       <h:outputText value="#{tarea.titulo}"/>
                      
                       </h:column>
                      
                       <h:column>
                       <f:facet name="header">
                       <h:panelGroup>
                       <h:outputText value="Fecha alta"/>
                       [
                       <h:commandLink actionListener="#{TareasPaginadorBean.sortLinkAsc}">
                       <f:attribute name="columna" value="alta"/>
                       <h:outputText id="ascTitle" value="asc"/>
                       </h:commandLink>
                      
                       <h:outputText value="|" />
                      
                       <h:commandLink actionListener="#{TareasPaginadorBean.sortLinkDec}" >
                       <f:attribute name="columna" value="alta"/>
                       <h:outputText id="decTitle" value="dec"/>
                       </h:commandLink>
                       ]
                       </h:panelGroup>
                       </f:facet>
                      
                       <h:outputText value="#{tarea.alta}"/>
                       </h:column>
                      
                       <h:column>
                       <h:outputText value="#{tarea.proyecto.titulo}" />
                       </h:column>
                       </rich:dataTable>
                       <rich:datascroller
                       scrollerListener="#{TareasPaginadorBean.actionList}"
                       for="tareasRC2"
                       id="tareasRC2Scroller"
                       fastStep="#{TareasPaginadorBean.elementosAvanceRapido}"
                       immediate="false">
                       <f:facet name="first" >
                       <h:outputText value="|<" />
                       </f:facet>
                       <f:facet name="last">
                       <h:outputText value=">|" />
                       </f:facet>
                       <f:facet name="previous">
                       <h:outputText value="<" />
                       </f:facet>
                       <f:facet name="next">
                       <h:outputText value=">" />
                       </f:facet>
                       <f:facet name="fastforward">
                       <h:outputText value=">>" />
                       </f:facet>
                       <f:facet name="fastrewind">
                       <h:outputText value="<<" />
                       </f:facet>
                       </rich:datascroller>


                      Thank you very much for your help :)

                      • 8. Re: Getting datascroller data
                        Juan Ignacio Sánchez Lara Apprentice

                        I forgot, aditionally data columns appear twice. Please excuse the post flooding :(

                        • 9. Re: Getting datascroller data
                          Juan Ignacio Sánchez Lara Apprentice

                          Excuse me, simply forget duplicate columns problem. Just embarrasing :$

                          • 10. Re: Getting datascroller data
                            Juan Ignacio Sánchez Lara Apprentice

                            This thread is almost turning into a monologue, but I must follow trying...

                            I think the problem is I am not reading right the information received. It doesn't render page numbers right now, so I'm always pushing "next", "first" and so on. Then the event can give me nothing but the pushed facet, not the "next page _number_".

                            I think I just have to find the right way to save the state (the actual page) and everything will just work.

                            Sorry for the inconvenience, folks

                            • 11. Re: Getting datascroller data
                              Juan Ignacio Sánchez Lara Apprentice

                              I promise this'll be the last one till I get help or a sollution. These are my problems right now:

                              a) It doesn't show pages numbers.
                              b) It doesn't trigger scrollerListener
                              c) DataTable 'value' method in the backing bean is called twice per request.

                              <rich:dataTable value="#{TareasPaginadorBean.tareas}"
                               var="tarea"
                               rowClasses="oddRow, evenRow"
                               headerClass="tableHeader"
                               id="tareasRC"
                               rows="#{TareasPaginadorBean.elementosPorPagina}">
                               <h:column>
                               <f:facet name="header">
                               <h:panelGroup>
                               <h:outputText value="Id"/>
                               </h:panelGroup>
                               </f:facet>
                               <h:outputText value="#{tarea.id}"/>
                               </h:column>
                               <h:column>
                               <f:facet name="header">
                               <h:panelGroup>
                               <h:outputText value="Título"/>
                               </h:panelGroup>
                               </f:facet>
                               <h:outputText value="#{tarea.titulo}"/>
                              
                               </h:column>
                              
                               <h:column>
                               <f:facet name="header">
                               <h:panelGroup>
                               <h:outputText value="Fecha alta"/>
                               </h:panelGroup>
                               </f:facet>
                              
                               <h:outputText value="#{tarea.alta}"/>
                               </h:column>
                              
                               <h:column>
                               <f:facet name="header">
                               <h:panelGroup>
                               <h:outputText value="Título del proyecto"/>
                               </h:panelGroup>
                               </f:facet>
                              
                               <h:outputText value="#{tarea.proyecto.titulo}" />
                               </h:column>
                               </rich:dataTable>
                               <rich:datascroller for="tareasRC" maxPages="20"
                               scrollerListener="#{TareasPaginadorBean.actionList}" />


                              Help! :(

                              • 12. Re: Getting datascroller data [SOLVED]
                                Juan Ignacio Sánchez Lara Apprentice

                                In brief, I've finally managed to make it work. Suggestion:

                                For the server side use Tomahawk myfaces-cars.zip example. I've modified it to work with Spring plus Hibernate. The only thing you should know is that you'll need one more getter in your BB which returns model.getWrappedData to the rich faces pager.

                                If anybody is interested, this is my code for both Tomahawk and RichFaces pagers:

                                <t:dataTable
                                 id="tareasT"
                                 var="tarea"
                                 preserveDataModel="true"
                                 binding="#{TareasPaginadorBean.datos}"
                                 value="#{TareasPaginadorBean.modelo.value}"
                                 rows="#{TareasPaginadorBean.modelo.rows}"
                                
                                 rowClasses="oddRow, evenRow"
                                 headerClass="tableHeader">
                                 <h:column>
                                 <h:outputText value="#{tarea.id}"/>
                                 </h:column>
                                 <h:column>
                                 <f:facet name="header">
                                 <h:panelGroup>
                                 <h:outputText value="Título"/>
                                 </h:panelGroup>
                                 </f:facet>
                                
                                 <h:outputText value="#{tarea.titulo}"/>
                                
                                 </h:column>
                                
                                 <h:column>
                                 <f:facet name="header">
                                 <h:panelGroup>
                                 <h:outputText value="Fecha alta"/>
                                 </h:panelGroup>
                                 </f:facet>
                                
                                 <h:outputText value="#{tarea.alta}"/>
                                 </h:column>
                                
                                 <h:column>
                                 <h:outputText value="#{tarea.proyecto.titulo}" />
                                 </h:column>
                                 </t:dataTable>
                                 <t:dataScroller
                                 id="tareasTScroller"
                                 for="tareasT"
                                 fastStep="#{TareasPaginadorBean.elementosAvanceRapido}"
                                 pageCountVar="pageCount"
                                 pageIndexVar="pageIndex"
                                 styleClass="scroller"
                                 paginator="true"
                                 paginatorMaxPages="9"
                                 paginatorTableClass="paginator"
                                 paginatorActiveColumnStyle="font-weight:bold;">
                                
                                 <f:facet name="first" >
                                 <h:outputText value="|<" />
                                 </f:facet>
                                 <f:facet name="last">
                                 <h:outputText value=">|" />
                                 </f:facet>
                                 <f:facet name="previous">
                                 <h:outputText value="<" />
                                 </f:facet>
                                 <f:facet name="next">
                                 <h:outputText value=">" />
                                 </f:facet>
                                 <f:facet name="fastforward">
                                 <h:outputText value=">>" />
                                 </f:facet>
                                 <f:facet name="fastrewind">
                                 <h:outputText value="<<" />
                                 </f:facet>
                                 </t:dataScroller>
                                
                                
                                
                                 <rich:dataTable
                                 id="tareasRF"
                                 var="tarea"
                                 binding="#{TareasPaginadorBeanAJAX.datos}"
                                 value="#{TareasPaginadorBeanAJAX.modelo.value}"
                                 rows="#{TareasPaginadorBeanAJAX.modelo.rows}"
                                 rowClasses="oddRow, evenRow"
                                 headerClass="tableHeader">
                                
                                 <f:facet name="header">
                                <rich:columnGroup>
                                 <rich:column>
                                 <h:outputText value="ID"/>
                                 </rich:column>
                                 <rich:column>
                                 <h:outputText value="Título"/>
                                 </rich:column>
                                 <rich:column>
                                 <h:outputText value="Fecha Alta"/>
                                 </rich:column>
                                 <rich:column>
                                 <h:outputText value="Título Proyecto"/>
                                 </rich:column>
                                </rich:columnGroup>
                                 </f:facet>
                                 <h:column>
                                 <h:outputText value="#{tarea.id}"/>
                                
                                 </h:column>
                                 <h:column>
                                 <h:outputText value="#{tarea.titulo}"/>
                                 </h:column>
                                
                                 <h:column>
                                 <h:outputText value="#{tarea.alta}"/>
                                 </h:column>
                                
                                 <h:column>
                                 <h:outputText value="#{tarea.proyecto.titulo}" />
                                 </h:column>
                                 </rich:dataTable>
                                 <rich:datascroller
                                 id="tareasRFScroller"
                                 for="tareasRF"
                                 fastStep="#{TareasPaginadorBeanAJAX.elementosAvanceRapido}"
                                 styleClass="scroller">
                                
                                 </rich:datascroller>