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

         <%@ 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" %>
               <link href="styles.css" rel="stylesheet" type="text/css"/>
               <title>Test komponentu przewijania</title>
                  <h:dataTable id="timezones" value="#{bb.data}" var="row" rows="10">
                        <h:selectBooleanCheckbox value="{bb.dummy}" onchange="submit()"/>
                        <h:outputText value="#{row}" />
                  <corejsf:pager dataTableId="timezones" 
                     showpages="20" selectedStyleClass="currentPage"/>
                     <h:commandButton value="foo"/>

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


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


          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):


          2) Create the mentioned file:


          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">

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


          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" 

            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" 

            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]
                 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


                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


                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


                  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");


                  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


                    • 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?