1 Reply Latest reply on Jul 10, 2008 3:02 PM by Stijn Cremers

    Paging tag with facelets

    Stijn Cremers Novice

      Hi Seam folks!


      I'm trying to make a paging tag based on this blog


      But i have tweaked the code a little. But i don't want to add the code snippet to all my pages, because it is a lot of code.


      So i want to make a custom tag, something like:



      <my:paging action="#{projectSearch.search}"/>



      That action attribute must come to all the commandLinks actions on the in the paging code.


      Is this possible?


      <c:choose>
                      
              <c:when test="#{page.simplePaging}">
                      <div id="paging">
      
                      <h:outputText 
                              value="Page #{page.pageIndex} of #{page.lastPageIndex} pages "
                              rendered="#{page.lastPageIndex > 1}"/>
      
                      <c:forEach var="i" begin="1" end="#{page.lastPageIndex}">
                              <h:commandLink action="#{projectSearchAction.search}">
                           <h:outputText value="#{i}"/>
                           <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                           <f:param name="pn" value="#{i}" />
                         </h:commandLink>
                         &#160;
                      </c:forEach>
                      
              </div>
              </c:when>
              
      
              <c:otherwise>
                      <div id="paging">
                              <h:outputText 
                                      value="Page #{page.pageIndex} of #{page.lastPageIndex} pages "
                                      rendered="#{page.lastPageIndex > 1}"/>
      
                              <h:commandLink action="#{projectSearchAction.search}" rendered="#{page.pageIndex != 1}">
                                      <h:outputText value="First"/>
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="1" />
                              </h:commandLink>
                              &#160;
                              <h:outputText value=" 1 " rendered="#{page.pageIndex == 1}"/>
                              
                              <h:commandLink action="#{projectSearchAction.search}" rendered="#{page.pageIndex != 1}">
                                      <h:outputText value="Previous"/>
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="#{page.pageIndex - 1}" />
                              </h:commandLink>
                              &#160;
                              <h:outputText value=" ... " rendered="#{page.leftDots}"/>
      
                              <c:forEach 
                                      var="i" 
                                      begin="#{page.pageIndex - page.leftSteps}"
                                      end="#{page.pageIndex - 1}">
      
                                      <h:commandLink action="#{projectSearchAction.search}">
                                      <h:outputText value="#{i}"/>
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="#{i}" />
                                      </h:commandLink>
                                      &#160;
                              </c:forEach>
      
                               <h:outputText 
                                      value=" #{page.pageIndex} "
                                      rendered="#{page.showPageIndex()}"/>
      
                              <c:forEach var="i" begin="#{page.pageIndex + 1}"
                                      end="#{page.pageIndex + page.rightSteps}">
                                      <h:commandLink action="#{projectSearchAction.search}">
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="#{i}" />
                                      </h:commandLink>
                                      &#160;
                              </c:forEach>
      
                              <h:outputText value=" ... " rendered="#{page.rightDots}"/>
      
                              <h:commandLink action="#{projectSearchAction.search}"
                                      rendered="#{page.pageIndex != page.lastPageIndex}">
                                      <h:outputText value="Next"/>
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="#{page.pageIndex + 1}" />
                              </h:commandLink>
                              
                              &#160;
                              
                              <h:commandLink action="#{projectSearchAction.search}"
                                      rendered="#{page.pageIndex != page.lastPageIndex}">
                                      <h:outputText value="Last"/>
                                      <f:param name="ps" value='#{ps != null ? ps : 0}'/>
                                      <f:param name="pn" value="#{page.lastPageIndex}" />
                              </h:commandLink>
                              
                              &#160;
                              
                              <h:outputText value=" #{page.lastPageIndex}"
                                      rendered="#{page.pageIndex == page.lastPageIndex}"/>
                      </div>
              </c:otherwise>
              
      </c:choose>