6 Replies Latest reply on Aug 31, 2007 6:29 AM by Natalia Ponomareva

    ClassCastException with @DataModel

    Todd Main Newbie

      I'm getting the following exception while using @DataModel with a h:dataTable component.

      Note that without the "@Out" annotations, my dataTables were always empty. Maybe that in itself is a clue, but I don't know how to debug it further.

      Also note that "document" is not null in my test case.

      Is there a problem with more than one @DataModel in a bean?

      Caused by: java.lang.ClassCastException: java.util.ArrayList
       at org.jboss.seam.databinding.DataModelBinder.isDirty(DataModelBinder.java:19)
       at org.jboss.seam.Component.outjectDataModelList(Component.java:973)
       at org.jboss.seam.Component.outjectDataModels(Component.java:937)
       at org.jboss.seam.Component.outject(Component.java:857)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:41)
       at sun.reflect.GeneratedMethodAccessor650.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
       at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:82)
       at sun.reflect.GeneratedMethodAccessor649.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
       at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:60)
       at sun.reflect.GeneratedMethodAccessor648.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
       at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:39)
       at sun.reflect.GeneratedMethodAccessor647.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:90)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
       at org.jboss.seam.ejb.SeamInterceptor.aroundInvokeInContexts(SeamInterceptor.java:73)
       at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:45)
       at sun.reflect.GeneratedMethodAccessor675.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       ... 48 more


      My Session Bean is:

      @Name("viewDocument")
      @Stateless
      public class ViewDocumentAction implements ViewDocument {
      
       @DataModel(value = "alerts")
       @Out
       private List alerts;
      
       @DataModelSelection(value="alerts")
       private Alert selectedAlert;
      
       @DataModel(value = "docevents")
       @Out
       private List docevents;
      
       @DataModelSelection(value="docevents")
       private DocumentEvent selectedEvent;
      
       @Out
       private Document document;
      
       @PersistenceContext
       private EntityManager em;
      
       @RequestParameter
       private String documentId;
      
       public String view() {
      
       long id = StringUtility.parseLong(documentId);
      
       document = em.find(Document.class, id);
      
       if (document != null) {
       // fetch alerts and events from db
       document.getEvents().size();
       document.getAlerts().size();
      
       alerts = new ArrayList(document.getAlerts());
       docevents = new ArrayList(document.getEvents());
       }
      
       return "/Document.xhtml";
       }
      



        • 1. Re: ClassCastException with @DataModel
          Alex Narinsky Newbie

          I have the same problem. Did you find a solution?
          Thanks!

          • 2. Re: ClassCastException with @DataModel
            Tony Herstell Master

            This might have helped... (scope page)

             // Used to diaply the final choices in the menu section
             @DataModel(value="finalKeywordsDatamodel", scope=ScopeType.PAGE)
             private LinkedHashSet<Keyword> finalKeywordsSet;
            
             // Used to diaply the final choices in the menu section
             @DataModel(value="finalCategoriesDatamodel", scope=ScopeType.PAGE)
             private LinkedHashSet<Category> finalCategoriesSet;
            


            But what really got me out of the poo was NOT using @DataModelSelection!


            Use EL instead and pass in the selected item (if you can) as a parameter as I have shown below (action="#{keywordsStepController.deleteKeyword(eachKeyword)}"):


             @DataModel(value="keywordsDatamodel", scope=ScopeType.PAGE)
             private LinkedHashSet<Keyword> keywordsSet;
            



            <h:dataTable var="eachKeyword" value="#{keywordsDatamodel}" rendered="#{keywordsDatamodel.rowCount>0}">
            
             <h:column>
             <f:facet name="header">
             <h:outputText value="#{messages.keyword}" />
             </f:facet>
             <h:outputText value="#{eachKeyword.keyword}" />
             </h:column>
            
             <h:column>
             <h:commandButton value="#{messages.button_delete}"
             action="#{keywordsStepController.deleteKeyword(eachKeyword)}"/>
             </h:column>
            </h:dataTable>
            



            I didnt put this in Jira.. but I could not get DataModelSelection to work for me!

            • 3. Re: ClassCastException with @DataModel
              Raffi Khatchadourian Newbie

              Hi. I tried not using the DataModelSelection as you have mentioned, however, I am getting a peculiar error:

              PWC6296: The function delete must be used with a prefix when a default namespace is not specified

              Any ideas?

              • 4. Re: ClassCastException with @DataModel
                Raffi Khatchadourian Newbie

                You can send params through EL? I didn't think that was possible with JSF. Am I mistaken?

                • 5. Re: ClassCastException with @DataModel
                  Pete Muir Master

                  You can with the extended EL Seam provides (JBoss EL)

                  • 6. Re: ClassCastException with @DataModel
                    Natalia Ponomareva Newbie

                    Get rid of the @Out and put @Factory annotations to the method, that fills this lists. I imagine it is view

                    @Name("viewDocument")
                    @Stateless
                    public class ViewDocumentAction implements ViewDocument {
                    
                     @DataModel(value = "alerts")
                     private List alerts;
                    
                     @DataModelSelection(value="alerts")
                     private Alert selectedAlert;
                    
                     @DataModel(value = "docevents")
                     private List docevents;
                    
                     @DataModelSelection(value="docevents")
                     private DocumentEvent selectedEvent;
                    
                     @Out
                     private Document document;
                    
                     @PersistenceContext
                     private EntityManager em;
                    
                     @RequestParameter
                     private String documentId;
                    
                     @Factory("alerts"")
                     @Factory("docevents")
                     public void view() {
                    
                     long id = StringUtility.parseLong(documentId);
                    
                     document = em.find(Document.class, id);
                    
                     if (document != null) {
                     // fetch alerts and events from db
                     document.getEvents().size();
                     document.getAlerts().size();
                    
                     alerts = new ArrayList(document.getAlerts());
                     docevents = new ArrayList(document.getEvents());
                     }
                    
                     }
                    
                    

                    once xhtml page sees need of alerts to be initiated, it will search for it factory method.