7 Replies Latest reply on Feb 27, 2009 7:32 PM by Piotr Salski

    pagination - jsp, xhtml, tld

    Piotr Salski Newbie

      In jsp I have found pagination that uses tld so I can add tag in jsp to display paging with dataTable, does anybody know how to do pagination using xhtml and dataTable?



      JSP page with working pagination



      <html>
         <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
         <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
         <%@ taglib uri="http://corejsf.com/pager" prefix="corejsf" %>
      
         <f:view>
            <head>                  
               <link href="styles.css" rel="stylesheet" type="text/css"/>
               <title>Test komponentu przewijania</title>
            </head>
            <body>
               <h:form>
                  <h:dataTable id="timezones" value="#{bb.data}" var="row" rows="10">
                     <h:column>
                        <h:selectBooleanCheckbox value="{bb.dummy}" onchange="submit()"/>
                     </h:column>
                     <h:column>
                        <h:outputText value="#{row}" />
                     </h:column>
                  </h:dataTable>
                  <corejsf:pager dataTableId="timezones" 
                     showpages="20" selectedStyleClass="currentPage"/>
                     <h:commandButton value="foo"/>
               </h:form>
            </body>
         </f:view>
      </html>
      


      I cant make it work in seam project with xhtml
      Link or sample may be helpfull


      Regards


        • 1. Re: pagination - jsp, xhtml, tld
          Nikos Paraskevopoulos Novice

          Hi,


          You need to define a Facelet tag for this job. Having the component and renderer ready for it, it is really easy.


          (I guess your code comes from http://www.javapassion.com/handsonlabs/jsfdatatable/)


          1) Add a context-param in web.xml (or modify the existing by appending the path to your file):


               <context-param>
                    <param-name>facelets.LIBRARIES</param-name>
                    <param-value>/WEB-INF/myOwnFacelet.taglib.xml</param-value>
               </context-param>
          



          2) Create the mentioned file:


          /WEB-INF/myOwnFacelet.taglib.xml



          3) The file contents like this:


          <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
          <facelet-taglib>
               <namespace>http://anything</namespace>
               <tag>
                    <tag-name>pager</tag-name>
                    <component>
                         <component-type>javax.faces.Output</component-type>
                         <renderer-type>com.corejsf.Pager</renderer-type>
                    </component>
               </tag>
          </facelet-taglib>
          



          4) Use it, by defining the proper namespace in your xhtml (note the URL must be the same as in .taglib.xml):


          <html
               xmlns="http://www.w3.org/1999/xhtml"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:c="http://java.sun.com/jstl/core" 
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:corejsf="http://anything" 
          >
          



          From http://www.javapassion.com/handsonlabs/jsfdatatable/ you need to keep the changes in faces-config.xml, and of course PageRenderer.java. The tag file and class are redundant in a Facelets environment.


          Hope it helps!

          • 2. Re: pagination - jsp, xhtml, tld
            Piotr Salski Newbie

            Thanks for reply,
            I tried to follow your steps. First I have problems with

            <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" 
            "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
            <facelet-taglib>
                 <namespace>http://corejsf.com/pager</namespace>
                 <tag>
                      <tag-name>pager</tag-name>
                      <component>
                           <component-type>javax.faces.Output</component-type>
                           <renderer-type>com.corejsf.Pager</renderer-type>
                      </component>
                 </tag>
            </facelet-taglib>


            even thought I have jsf-facelets.jar in librares I get worning


            The file cannot be validated as the XML Schema "http://java.sun.com/dtd/facelet-taglib_1_0.dtd" 
            that is specified as describing the syntax of the file cannot be located.
                 pagerfacelet.taglib.xml     paging/WebContent/WEB-INF     line 2     XML Problem
            


            I tried to use just facelet-taglib10.dtd

            <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" 
            "facelet-taglib_1_0.dtd">
            <facelet-taglib>
                 <namespace>http://corejsf.com/pager</namespace>
                 <tag>
                      <tag-name>pager</tag-name>
                      <component>
                           <component-type>javax.faces.Output</component-type>
                           <renderer-type>com.corejsf.Pager</renderer-type>
                      </component>
                 </tag>
            </facelet-taglib>>

            by adding facelet-taglib10.dtd into WEB-INF still I've got worning and finally error when try to run it :(


            20:35:47,247 ERROR [STDERR] 2009-02-25 20:35:47 com.sun.facelets.compiler.TagLibraryConfig loadImplicit
            INFO: Added Library from: jar:file:/C:/jbdevstudio/jboss-eap/jboss-as/server/default/deploy/paging.war/WEB-INF/lib/jboss-seam-ui.jar!/META-INF/seam-ui.taglib.xml
            20:35:47,720 INFO  [STDOUT] Hibernate: select aaa0_.id as id2_, aaa0_.name as name2_, aaa0_.version as version2_ from aaa aaa0_
            20:35:47,748 ERROR [STDERR] 2009-02-25 20:35:47 com.sun.facelets.FaceletViewHandler handleRenderException
            SEVERE: Error Rendering View[/aaaList.xhtml]
            java.lang.NullPointerException
                 at com.corejsf.PagerRenderer.encodeBegin(PagerRenderer.java:17)
                 at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:808)
                 at org.ajax4jsf.framework.renderer.RendererBase.renderChild(RendererBase.java:280)
                 at org.ajax4jsf.framework.renderer.RendererBase.renderChildren(RendererBase.java:262)
                 at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:189)
                 at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:184)
                 at org.ajax4jsf.framework.renderer.RendererBase.encodeChildren(RendererBase.java:121)



            It is pointing to PagerRenderer.class which I heve in scr/model in package com.corejsf


            Is it because of facelet-taglib10.dtd ????

            • 3. Re: pagination - jsp, xhtml, tld
              Nikos Paraskevopoulos Novice

              Hello again,


              Is the NullPointerException in this line:


              while (!(parent instanceof UIForm)) parent = parent.getParent();



              If so, make sure that the <corejsf:pager> is included in a <h:form>, just like the example from javapassion.com.


              As for the DTD, it is most probably irrelevant to the error. Never mind it for now, since it will not stop your development, just annoy you with the warnings.


              Good luck!

              • 4. Re: pagination - jsp, xhtml, tld
                Piotr Salski Newbie

                Great many thanks


                That was the problem, h:form worked fine but...


                in tld file, showpages is set as integer


                attribute> 
                         <name>showpages</name>
                         <deferred-value>
                            <type>int</type>
                         </deferred-value>         
                      </attribute>
                


                and in pageRenderer it is passed to integer as well


                 Integer a = (Integer) component.getAttributes().get("showpages");
                



                but if I will not set a to static for example like this


                Integer a = 20;



                and will not remove from xhtml file


                showpages="20"



                I will get error


                java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer



                how come????


                • 5. Re: pagination - jsp, xhtml, tld
                  Nikos Paraskevopoulos Novice

                  Hi,


                  About the ClassCastException: The TLD is irrelevant, as Facelets uses a completely different technology than JSP for custom tags. So you have a problem indeed. Based on a similar case I had run into, I suggest replacing the renderer code:


                  Integer a = (Integer) component.getAttributes().get("showpages");
                  



                  with:


                  Object o = component.getAttributes().get("showpages");
                  Integer showpages = null;
                  if( o != null ) {
                      if( o instanceof Integer ) showpages = (Integer) o;
                      else if( o instanceof String ) showpages = Integer.valueOf((String) o);
                      ...and so on, you could also check if o is Number...
                  }
                  






                  Another suggestion:

                  The code you are using from the lab page is OK for lab purposes, but I dont think it is really suitable for production applications. In either case I suggest you consider RichFaces. It is much richer and more professional.

                  • 6. Re: pagination - jsp, xhtml, tld
                    Piotr Salski Newbie

                    O meeeen


                    RichFaces is working without any problem and it looks so nice.


                    Ones again thanks for all your HELP


                    Regards

                    • 7. Re: pagination - jsp, xhtml, tld
                      Piotr Salski Newbie

                      One more thing, do you know why richfaces is not displaying properly in firefox and it is OK in IE ??
                      Is there solution for this?