2 Replies Latest reply on May 12, 2010 5:13 AM by Nick Belaevski

    ClassCastException when sorting a datatable

    Jana Stefkova Newbie

      Hi,

       

      i have a datatable with a column that has objects of type Object. in this column i have then String and Long values. when i do sorting on the column, i get ClassCastException:

       

      14:22:20,090 ERROR [STDERR] 11.05.2010 14:22:20 com.sun.facelets.FaceletViewHandler handleRenderException
      SCHWERWIEGEND: Error Rendering View[/pages/worklist/main/worklistMain.xhtml]
      java.lang.ClassCastException: java.lang.Long
           at java.lang.String.compareTo(String.java:90)
           at org.richfaces.model.impl.expressive.WrappedBeanComparator2.compare(WrappedBeanComparator2.java:102)
           at org.richfaces.model.impl.expressive.WrappedBeanComparator2.compare(WrappedBeanComparator2.java:80)
           at java.util.Arrays.mergeSort(Arrays.java:1284)
           at java.util.Arrays.mergeSort(Arrays.java:1295)
           at java.util.Arrays.mergeSort(Arrays.java:1295)
           at java.util.Arrays.sort(Arrays.java:1223)
           at java.util.Collections.sort(Collections.java:159)
           at org.richfaces.model.ModifiableModel.sort(ModifiableModel.java:273)
           at org.richfaces.model.ModifiableModel.modify(ModifiableModel.java:241)
           at org.richfaces.model.ExtendedTableDataModifiableModel.modify(ExtendedTableDataModifiableModel.java:114)
           at org.richfaces.component.UIExtendedDataTable.createDataModel(UIExtendedDataTable.java:376)
           at org.ajax4jsf.component.UIDataAdaptorBase.getExtendedDataModel(UIDataAdaptorBase.java:621)
           at org.ajax4jsf.component.UIDataAdaptorBase.getRowCount(UIDataAdaptorBase.java:248)
           at org.richfaces.renderkit.html.ExtendedDataTableRenderer.doEncodeBegin(ExtendedDataTableRenderer.java:284)
           at org.richfaces.renderkit.html.ExtendedDataTableRenderer.doEncodeBegin(ExtendedDataTableRenderer.java:196)
           at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:100)
           at org.richfaces.renderkit.AbstractExtendedTableRenderer.encodeBegin(AbstractExtendedTableRenderer.java:1365)
           at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
           at javax.faces.component.UIData.encodeBegin(UIData.java:967)
           at org.ajax4jsf.component.UIDataAdaptorBase.encodeBegin(UIDataAdaptorBase.java:1225)
           at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:275)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
           at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
           at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:124)
           at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:685)
           at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:556)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
      
      

       

      this is because it tries to compare the String with the Long, but the String can compare only with a String.