I'm sure I am doing something wrong, but I can't figure out what it is. I have the following:

   <h:form>
       <h:commandButton action="#{dataSourceEditor.newProperty}"
           value="New Property" />
       <p></p>
<t:dataTable value="#{dataSourceEditor.dataModel}" preserveDataModel="true"
           var="property" border="1">
           <h:column>
               <h:inputText value="#{property.name}" />
           </h:column>
           <h:column>
               <h:outputText value="#{property.type}" />
               <h:inputHidden value="#{property.type}" />
           </h:column>
       </t:dataTable>
   </h:form>

My dataSourceEditor bean is in request scope and has the following methods.

   public DataModel getDataModel() {
       if (dataModel == null) {
           dataModel = new ListDataModel();
       }

       dataModel.setWrappedData(properties);

       return dataModel;
   }


   public void setDataModel(DataModel dm) {
       dataModel = dm;
   }

   public String newProperty() {
       DSProperty property = new DSProperty();
       property.setName("new property");
       property.setType(Property.LONG);

       if (dataModel != null) {
           properties = (List) dataModel.getWrappedData();
       }

       if (properties == null) {
           properties = new ArrayList();
       }

       properties.add(property);

       return null;
   }

When I click the "new property" button I would expect my "setDataModel" method to be called then the "newProperty" method to be called where I add a new property to the list. However, when I click on the "new property" button I get the following class cast exception.

java.lang.ClassCastException: javax.faces.model.ListDataModel
at org.apache.myfaces.component.html.ext.HtmlDataTable.updateModelFromPreservedDataModel(HtmlDataTable.java:254) at org.apache.myfaces.component.html.ext.HtmlDataTable.processUpdates(HtmlDataTable.java:240)
        at javax.faces.component.UIForm.processUpdates(UIForm.java:196)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:927)
        at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:363)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:81)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
        at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at org.apache.beehive.netui.pageflow.PageFlowPageFilter.runPage(PageFlowPageFilter.java:299) at org.apache.beehive.netui.pageflow.PageFlowPageFilter.doFilter(PageFlowPageFilter.java:214) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilter.java:285) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at com.bea.p13n.servlets.PortalServletFilter.doFilter(PortalServletFilter.java:329) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3192) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1984) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1891) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1318)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)

I am completely stumped about why this happens. Thanks in advance for your help.

Randy


Reply via email to