8 Replies Latest reply on Oct 20, 2012 9:55 PM by zenig

    org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder

    zenig Newbie

      I have a project with Richfaces 4.2.2 Final. I setup a dataTable with sorting per the showcase and when I access the page, I get the following error. What could I be doing wrong? I can only think my maven POM is setup wrong (ear) and somehow referencing separate objects...

       

      java.lang.ClassCastException: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder

      org.richfaces.component.UIColumn.getSortOrder(UIColumn.java:187)

      org.richfaces.component.AbstractColumn.getSortField(AbstractColumn.java:147)

      org.richfaces.component.UIDataTableBase.createArrangeableState(UIDataTableBase.java:261)

      org.richfaces.component.UIDataTableBase.createExtendedDataModel(UIDataTableBase.java:234)

      org.richfaces.component.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:459)

      org.richfaces.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:272)

      org.richfaces.renderkit.AbstractTableRenderer.encodeTableFacets(AbstractTableRenderer.java:118)

      org.richfaces.renderkit.DataTableRenderer.doEncodeBegin(DataTableRenderer.java:303)

      org.richfaces.renderkit.RendererBase.encodeBegin(RendererBase.java:115)

      javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)

      javax.faces.component.UIComponent.encodeAll(UIComponent.java:1777)

      javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)

      javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)

      com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)

      com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)

      org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:88)

      javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)

      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)

      com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

      javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

        • 1. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
          zenig Newbie

          I am using JBoss AS 7.1.1. Could it be two different classloaders are loading SortOrder thus the casting can't happen? Is it in part due to the EAR structure?

           

          Here are my Maven snippets:

           

          Root POM.xml:

          <dependency>

                          <groupId>org.richfaces</groupId>

                          <artifactId>richfaces-bom</artifactId>

                          <version>${richfaces.version}</version>

                          <type>pom</type>

                          <scope>import</scope>

                      </dependency>

           

           

                      <dependency>

                          <groupId>org.richfaces.ui</groupId>

                          <artifactId>richfaces-components-ui</artifactId>

                          <version>${richfaces.version}</version>

                      </dependency>

           

           

                              <dependency>

                          <groupId>org.richfaces.ui</groupId>

                          <artifactId>richfaces-components-api</artifactId>

                          <version>${richfaces.version}</version>

                      </dependency>

           

                      <dependency>

                          <groupId>org.richfaces.core</groupId>

                          <artifactId>richfaces-core-impl</artifactId>

                          <version>${richfaces.version}</version>

                      </dependency>           

           

                                        <dependency>

                                                  <groupId>org.richfaces.core</groupId>

                                                  <artifactId>richfaces-core-api</artifactId>

                                                   <version>${richfaces.version}</version>

                                        </dependency>

           

          EJB POM.xml:



          <dependency>

                          <groupId>org.richfaces.ui</groupId>

                          <artifactId>richfaces-components-ui</artifactId>




          <scope>provided</scope>

                      </dependency>



          <dependency>

                          <groupId>org.richfaces.ui</groupId>

                          <artifactId>richfaces-components-api</artifactId>

                      </dependency>

           

          Web POM.xml:

          <dependency>

                      <groupId>org.richfaces.ui</groupId>

                      <artifactId>richfaces-components-ui</artifactId>

                  </dependency>

                       <dependency>

                      <groupId>org.richfaces.core</groupId>

                      <artifactId>richfaces-core-impl</artifactId>

                  </dependency>

          • 2. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
            Radim Hanus Expert

            it's obviously a classloading problem I had a similar one

            check if you have richfaces libs in your deployment either in project.ear/lib or project.ear/app.war/WEB-INF/lib directory

            if so then delete them and try if it helps

            • 3. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
              zenig Newbie

              Here is where the Richfaces libs reside. I am surprised to see the different filenames. In the EAR POM file, I use a property to specify the version ( ${richfaces.version} ) which is set to 4.3.0-SNAPSHOT. The EJB and WAR POM doesn't specify a version so it should use the version from the EAR POM, right? What do I have wrong?

               

              EAR (lib):

                        richfaces-components-api-4.3.0-SNAPSHOT.jar

                        richfaces-core-api-4.3.0-SNAPSHOT.jar

               

              WAR (WEB-INF\lib):

                        richfaces-components-api-4.3.0-20121011.103434-144.jar

                        richfaces-components-ui-4.3.0-20121005.112837-143.jar

                        richfaces-core-api-4.3.0-20121005.105055-103.jar

                        richfaces-core-impl-4.3.0-20121005.105302-98.jar

              • 4. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
                Radim Hanus Expert

                The EJB and WAR POM doesn't specify a version so it should use the version from the EAR POM, right?

                it depends on project pom.xml hierarchy, obviously your ear pom.xml is not connected with war pom.xm anyway

                if not defined the concrete version (4.3.0-SNAPSHOT at your case) is resolved in conjunction with top-level maven config $HOME/.m2/settings.xml

                What do I have wrong?

                I guest you need richfaces libs only in war so you should remove ear/ejb pom richfaces dependecies and define property ${richfaces.version} in war pom.xml

                as a final hint I would use latest stable version which is 4.2.2 now unless you need a specific feature/bugfix available only in snapshot

                • 5. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
                  zenig Newbie

                  it depends on project pom.xml hierarchy, obviously your ear pom.xml is not connected with war pom.xm anyway

                  if not defined the concrete version (4.3.0-SNAPSHOT at your case) is resolved in conjunction with top-level maven config $HOME/.m2/settings.xml

                  Your right, I didn't explain it correctly. I have a root POM and an EAR, Web and EJB POM. The EAR, Web, and EJB POM all use the root POM as the parent. With the version defined in the root POM, I figured the child POM files would use the version specified in the root POM. I looked at $HOME/.m2/settings.xml and largely the file is commented out (out-of-the-box).

                  I guest you need richfaces libs only in war so you should remove ear/ejb pom richfaces dependecies and define property ${richfaces.version} in war pom.xml

                  as a final hint I would use latest stable version which is 4.2.2 now unless you need a specific feature/bugfix available only in snapshot

                  I believe I need to have richfaces in the EJB POM since I am using org.richfaces.component.SortOrder and org.richfaces.component.UICalendar. If I don't have those, then it won't compile. I explicitly specified the Richfaces version in the Web POM and it is still pulling the jar files with the timestamp, opposed to 4.3.0-SNAPSHOT like the api jars!

                  • 6. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
                    Radim Hanus Expert

                    I looked at $HOME/.m2/settings.xml and largely the file is commented out (out-of-the-box).

                    you would need to configure your repositories following this guide

                     

                    your root pom.xml should maintain following dependencies:

                    <dependencyManagement>

                    <dependencies>

                    <dependency>

                    <groupId>org.richfaces</groupId>

                    <artifactId>richfaces-bom</artifactId>

                    <version>${richfaces.version}</version>

                    <scope>import</scope>

                    <type>pom</type>

                    </dependency>

                    </dependencies>

                    </dependencyManagement>

                     

                    <dependency>

                    <groupId>org.richfaces.ui</groupId>

                    <artifactId>richfaces-components-api</artifactId>

                    <scope>provided</scope>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.ui</groupId>

                    <artifactId>richfaces-components-ui</artifactId>

                    <scope>provided</scope>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.core</groupId>

                    <artifactId>richfaces-core-api</artifactId>

                    <scope>provided</scope>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.core</groupId>

                    <artifactId>richfaces-core-impl</artifactId>

                    <scope>provided</scope>

                    </dependency>

                     

                    since you need RF libs in ejb and war module simultaneously then these libs should be located in ear/lib but ideally nowhere else

                    delete any richfaces dependencies from ejb and war pom.xml and in your ear pom.xml override RF deps:

                    <dependency>

                    <groupId>org.richfaces.ui</groupId>

                    <artifactId>richfaces-components-api</artifactId>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.ui</groupId>

                    <artifactId>richfaces-components-ui</artifactId>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.core</groupId>

                    <artifactId>richfaces-core-api</artifactId>

                    </dependency>

                     

                    <dependency>

                    <groupId>org.richfaces.core</groupId>

                    <artifactId>richfaces-core-impl</artifactId>

                    </dependency>

                    hopefully it helps you

                    • 7. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
                      Radim Hanus Expert

                      I've just recalled a better solution:

                      1. create a richface4 module in jboss7 as described here:
                      2. then only your root pom.xml is supposed to maintain dependecies to richfaces libs with provided scope (delete any richfaces dependencies from ear, ejb, war ... pom.xm)
                      3. supply ear/META-INF/jboss-deployment-structure.xml as described in the JIRA issue

                      as a pretty side-effect your ear will be smaller

                      • 8. Re: org.richfaces.component.SortOrder cannot be cast to org.richfaces.component.SortOrder
                        zenig Newbie

                        Thank you. After following your feedback, it is now working. Hopefully this can help someone else with their EAR structure and Richfaces.