11 Replies Latest reply on Apr 20, 2011 12:11 AM by ramkumarps

    componentState of ExtendedDataTable

    nimo stephan Master

      I have a rich:extendedDataTable:

      <rich:extendedDataTable id="myDataTable" componentState="#{myBean.myDataTable}"
      id="dataTableViewApplications" value="#{myBean.myList}" var="list"
      tableState="#{myBean.myTableState}">
       ..
      </rich:extendedDataTable>



      now I want to get this instance by code (without using binding-attribute!):

      I guess, there are only two alternatives:

      - via findComponent
      - via componentState (???)


      I click the button:
      <a4j:commandButton action="#{myBean.snapshotDataTable}" value="Get my datatable"/>



      Look at my code:

      public void snapshotDataTable()
      {
      FacesContext context = FacesContext.getCurrentInstance();
      UIViewRoot view = context.getViewRoot();
      
      log.info("CLASS FOUND: #0", view.findComponent(":form:myDataTable").getClass());
      
      HtmlExtendedDataTable myDT = (HtmlExtendedDataTable) view.findComponent(":form:myDataTable");
      
       }


      Look at my log-file:

      10:58:38,435 INFO [MyBean] CLASS FOUND: org.richfaces.component.html.HtmlExtendedDataTable
      10:58:38,451 FATAL [application] java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable
      javax.faces.el.EvaluationException: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable
       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)


      You see, even I have found the right class "HtmlExtendedDataTable", it cannot be casted. Why? How can I solve that?

      (By the way, for what is the attribute "componentState" ???
      I bound it to a HtmlExtendedDataTable-Instance, but it does not work. So I used the findComponent-Approach, which does not work, either:-(

        • 1. Re: componentState of ExtendedDataTable
          Ilya Shaikovsky Master

          use tableState and explore please API docs for ExtendedDataTableState class. You should bind the table state to the object of this class.

          • 2. Re: componentState of ExtendedDataTable
            nimo stephan Master

            I know the ExtendedDataTableState-API and the HtmlExtendedDataTable.

            I want to make use of the method .getTableState of HtmlExtendedDataTable or vice versa .getExtendedDataTableState of ExtendedDataTableState.

            You should bind the table state to the object of this class.


            Yes, I know. Have done that and it works.

            But my Problem is described as the topic above, I want to have access to my HtmlExtendedDataTable but have a class-cast-ex even I have the right class (I do not want to use binding-property!):

            // throws class cast ex
            HtmlExtendedDataTable myDT = (HtmlExtendedDataTable) view.findComponent(":form:myDataTable");


            // throws class cast ex
            ExtendedDataTableState.getExtendedDataTableState((UIExtendedDataTable) view.findComponent(":form:myDataTable"));


            I want to have a button which saves the current table state programmatically, so I guess, I need to have access to my datatable instance via code. Or?


            • 3. Re: componentState of ExtendedDataTable
              nimo stephan Master

              The table-state changes when the user changes the state of the datatable.

              Imagine, I want to make restore-points, the user can click from a list all available table-states and then the table-state switches.

              The only problem is, I want to controll, when a table state should be saved.

              So I need a button "save State"..hence I need access to my datatable via code and get the class cast ex. (I do not want to use binding!)

              • 4. Re: componentState of ExtendedDataTable
                Ilya Shaikovsky Master

                Which project packaging you use? EAR, war? If EAR seems you just placed RF jars in wrong places. the exception could be appeared because of different class loaders problem.

                • 5. Re: componentState of ExtendedDataTable
                  nimo stephan Master

                  I use a EAR:

                  in my EAR:

                  richfaces-api-*.jar
                  richfaces-impl-*.jar
                  richfaces-ui-*.jar

                  in my WAR:

                  richfaces-impl-*.jar
                  richfaces-ui-*.jar

                  I use richfaces 3.3.0.

                  • 6. Re: componentState of ExtendedDataTable
                    Ilya Shaikovsky Master

                    should be


                    in my EAR:

                    richfaces-api-*.jar


                    only.

                    • 7. Re: componentState of ExtendedDataTable
                      nimo stephan Master

                      I changed it but it does not help:

                      Caused by: javax.faces.el.EvaluationException: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable
                       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
                       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
                       ... 54 more
                      Caused by: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable


                      but it s definitly the same class:

                      10:58:38,435 INFO [MyBean] CLASS FOUND: org.richfaces.component.html.HtmlExtendedDataTable



                      • 8. Re: componentState of ExtendedDataTable
                        Nick Belaevski Master

                         

                        "nimo22" wrote:
                        I changed it but it does not help:

                        Caused by: javax.faces.el.EvaluationException: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable
                         at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
                         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
                         ... 54 more
                        Caused by: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable


                        but it s definitly the same class:

                        10:58:38,435 INFO [MyBean] CLASS FOUND: org.richfaces.component.html.HtmlExtendedDataTable

                        How about #getClassLoader() call? Will it return the same values?

                        • 9. Re: componentState of ExtendedDataTable
                          nimo stephan Master

                          Hey ilya:

                          should be

                          Quote:

                          in my EAR:

                          richfaces-api-*.jar


                          only.


                          When I ommit the from my EAR (!)

                          then I get this failure:

                          Caused by: java.lang.NoClassDefFoundError: org/richfaces/component/html/HtmlExtendedDataTable
                           at java.lang.Class.getDeclaredMethods0(Native Method)
                           at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
                           at java.lang.Class.privateGetPublicMethods(Unknown Source)
                           at java.lang.Class.getMethods(Unknown Source)
                           at org.jboss.seam.Component.hasAnnotation(Component.java:1119)
                           at org.jboss.seam.Component.<init>(Component.java:232)
                           at org.jboss.seam.Component.<init>(Component.java:219)
                           at org.jboss.seam.init.Initialization.addComponent(Initialization.java:998)
                           ... 93 more


                          So I put this in my EAR:

                          richfaces-api-*.jar
                          richfaces-impl-*.jar
                          richfaces-ui-*.jar


                          then no java.lang.NoClassDefFoundError occurs.

                          In my WAR all three are in, too. (I have definitly a EAR-Project!)

                          Hello nbelaevski (how are u?:)

                          well I my classLoader:

                          07:42:05,398 INFO [MyBean] class loader: WebappClassLoader
                           delegate: false
                           repositories:
                           /WEB-INF/classes/
                          ----------> Parent Classloader:
                          java.net.FactoryURLClassLoader@42c93e
                          
                          07:42:05,398 FATAL [application] java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable
                          javax.faces.el.EvaluationException: java.lang.ClassCastException: org.richfaces.component.html.HtmlExtendedDataTable


                          • 10. Re: componentState of ExtendedDataTable
                            nimo stephan Master

                            When I only have the richfaces-api-*.jar in my EAR, then I get a java.lang.NoClassDefFoundError.

                            So I put all three jars in it and then no "NoClassDefFoundError" occurs.

                            (I use SEAM 2.1 and my EAR was created by SEAM!)

                            • 11. Re: componentState of ExtendedDataTable
                              ramkumarps Newbie

                              hey Stephan,

                               

                               

                              this problem is happening bcos of two different Jar files are there in ur EAR, one in EAR/Lib and other in Web-inf/lib

                               

                              use this below snipet in WAR project

                               

                              public void resetDataTable(){

                                                  UIComponent uiCombo = FacesContext.getCurrentInstance().getViewRoot().findComponent("mediationBeanForm:fileListDiv:fileListTable");

                                                  if(uiCombo!=null){

                                                            HtmlExtendedDataTable table = (HtmlExtendedDataTable) uiCombo;

                                                            Iterator<UIComponent> itr = table.columns();

                                                            System.out.println("table.getTableState() : "+table.getTableState());

                                                            if(itr!=null)

                                                            while(itr.hasNext()){

                                                                      UIComponent uiCom= itr.next();

                                                                      System.out.println("Component class "+uiCom.getClass().getName());

                                                                      Column col =(Column)uiCom;

                                                                      col.setSortOrder(Ordering.UNSORTED);

                                                                      col.setFilterValue("");

                                                            }

                                                            table.restoreOrigValue();

                                                  }

                                        }

                               

                              add the below line in Component.xml

                               

                              <component class="com.model.seam.ExtendedSupport" name="extendedSupport" precedence="20" scope="APPLICATION"/>

                               

                              now u can able to access this method in Xhtml