1 Reply Latest reply on Sep 17, 2005 2:34 AM by fancyh

    Throw ClassCastException when cast a JSF dataTable row to a

    fancyh

      Below codes will cause a ClassCastException:

      FacesContext facesContext = FacesContext.getCurrentInstance();
      UIViewRoot root = facesContext.getViewRoot();
      UIData table = (UIData)
      root.findComponent("listAlldata");
      Object row = table.getRowData();
      logger.info(" *** the row is " + row);
      logger.info(" *** the row classloader is " + row.getClass().getClassLoader());
      logger.info(" *** the new WebUser classloader is " + WebUser.class.getClassLoader());

      WebUser webUser = (WebUser) row;

      --------------------------------------------------------------------------------------
      The debug info are:

      17:05:54,078 INFO [WebUserListForm] *** the row classloader is org.jboss.mx.lo
      ading.UnifiedClassLoader3@70c242{ url=file:/D:/software/jboss-4.0.2/server/all/t
      mp/deploy/tmp41284ljsfc.ejb3 ,addedOrder=45}
      17:05:54,078 INFO [WebUserListForm] *** the new WebUser classloader is WebappC
      lassLoader
      delegate: false
      repositories:
      /WEB-INF/classes/
      ----------> Parent Classloader:
      java.net.FactoryURLClassLoader@19d56e9

      17:05:54,078 ERROR [MethodBindingImpl] Exception while invoking expression #{web
      UserListForm.showDetail}
      java.lang.ClassCastException: cn.com.ljintl.ljsfc.model.WebUser
      at cn.com.ljintl.ljsfc.web.WebUserListForm.showDetail(WebUserListForm.ja
      va:80)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
      :138)

      --------------------------------------------------------------------------------------
      The cn.com.ljintl.ljsfc.model.WebUser is very simple ejb3.0 entity class and is included in ljsfc.ejb3.

      The client jsp use a JSF dataTable,and there is a ljsfc-client.jar file in the
      WEB-INF\lib which also include a cn.com.ljintl.ljsfc.model.WebUser class.

      The JSF codes are:
      <x:dataTable id="listAlldata"
      styleClass="scrollerTable"
      headerClass="standardTable_Header"
      footerClass="standardTable_Header"
      rowClasses="standardTable_Row1,standardTable_Row2"
      columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column"
      var="webUser"
      value="#{webUserListForm.list}"
      preserveDataModel="true"
      rows="10"
      >
      <h:column>
      <f:facet name="header">
      </f:facet>

      <x:commandLink action="#{webUserListForm.showDetail}" immediate="true" >
      <h:outputText value="#{webUser.loginId}" />
      </x:commandLink>
      </h:column>


      ================================================
      How can i fix such bug?