1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default ClassCastException for SimpleComboBox into EditableGrid

    ClassCastException for SimpleComboBox into EditableGrid


    Hi, I have a ClassCastException when try to recreate EditableGrid example.

    Code:
    ....
    
    grid = new EditorGrid<TestDetail>(store, this.createColumnModel());
    grid.setBorders(true);
    grid.setAutoExpandColumn("id");
    grid.getSelectionModel().setSelectionMode(Style.SelectionMode.SINGLE);
    mainPanel.add(grid);
    
    ....
    
        public ColumnModel createColumnModel() {
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    ...
    ColumnConfig idColumn = new ColumnConfig();
    idColumn.setId("id");
    idColumn.setHeader("ID");
    idColumn.setFixed(true);
    configs.add(idColumn);
    
    final SimpleComboBox<EnumTest> permissionComboBox = new SimpleComboBox<EnumTest>();
    permissionComboBox.setForceSelection(true);
    permissionComboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
    permissionComboBox.add(EnumTest.getAll()); // getAll() return a List<EnumTest>
    
    CellEditor comboEditor = new CellEditor(permissionComboBox);
    
    ColumnConfig permissionColumn = new ColumnConfig();
    permissionColumn.setId("permission");
    permissionColumn.setHeader("Permission");
    permissionColumn.setWidth(150);
    permissionColumn.setEditor(comboEditor);
    configs.add(permissionColumn);
    
    return new ColumnModel(configs);
    }
    I view a combo as a label and when select this, the combo compare forword it and I have this error:
    Code:
    00:01:27,643 [ERROR] Uncaught exception escaped
    java.lang.ClassCastException: test.EnumTest cannot be cast to com.extjs.gxt.ui.client.data.ModelData     at com.extjs.gxt.ui.client.widget.form.ComboBox.setValue(ComboBox.java:1)     at com.extjs.gxt.ui.client.widget.Editor.startEdit(Editor.java:446)     at com.extjs.gxt.ui.client.widget.grid.EditorSupport.deferStartEditing(EditorSupport.java:217)     at com.extjs.gxt.ui.client.widget.grid.EditorSupport$2.run(EditorSupport.java:148)     at com.google.gwt.user.client.Timer.fire(Timer.java:149)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)     at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)     at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)     at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)     at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)     at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)     at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)     at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)     at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)     at com.google.gwt.core.client.impl.Impl.apply(Impl.java)     at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)     at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at java.lang.reflect.Method.invoke(Method.java:597)     at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)     at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)     at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)     at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)     at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)     at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)     at java.lang.Thread.run(Thread.java:662)
    Thanks
    Last edited by listirer; 3 Feb 2012 at 12:15 AM. Reason: error into code folding

  2. #2
    Sencha User
    Join Date
    Nov 2009
    Posts
    51
    Vote Rating
    0
    smiletolead is on a distinguished road

      0  

    Default


    Change
    Code:
    final SimpleComboBox<EnumTest>permissionComboBox = new SimpleComboBox<EnumTest>();
    to
    Code:
    final SimpleComboBox<String> permissionComboBox = new SimpleComboBox<String>();
    Because you are adding strings to the combo box in the following lines.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default


    Sorry, that is a typo, I have correct the previous post.
    Last edited by listirer; 3 Feb 2012 at 12:13 AM. Reason: shift the typo

  4. #4
    Sencha User
    Join Date
    Nov 2009
    Posts
    51
    Vote Rating
    0
    smiletolead is on a distinguished road

      0  

    Default


    Then make sure that EnumTest is a type of ModelData. You can do this by making EnumTest extend BaseModelData(which implements ModelData).

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default


    TestDetail extends BeanModel, and EnumTest is a property of TestDetail.
    This works in my (little) experience when I add a combo into a form.
    Here, I add the combo into a CellEditor and the latter into a ColumnConfig.
    So setId method maybe produce this problem...
    Last edited by listirer; 3 Feb 2012 at 1:24 AM. Reason: ID

  6. #6
    Sencha User
    Join Date
    Nov 2009
    Posts
    51
    Vote Rating
    0
    smiletolead is on a distinguished road

      0  

    Default


    Please post EnumTest class. It might be of some help

  7. #7
    Sencha User
    Join Date
    Nov 2009
    Posts
    51
    Vote Rating
    0
    smiletolead is on a distinguished road

      0  

    Default


    The cell editor you have used for the 'combo box' column does not override preProcessValue() and postProcessValue() methods. Refer the GXT examples. This is the reason you are getting those exceptions.

    The method preProcessValue() is called before combobox appears in the grid. This method retrieves the model corresponding to the value appearing in the cell which is being edited.

    The method postProcessValue() is called after the editing is complete. In this method, you return the value from the selected combobox model. The returned value will be shown in the grid cell.

  8. #8
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default


    smiletolead thanks for the support!
    I have fixed:
    Code:
    CellEditor comboEditor = new CellEditor(permissionComboBox) {
    
        @Override
        public Object preProcessValue(Object value) {
            if (value == null) {
                return value;
            }
            return permissionComboBox.findModel((EnumTest) value);
        }
    
        @Override
        public Object postProcessValue(Object value) {
            if (value == null) {
                return value;
            }
            return ((SimpleComboValue<EnumTest>) value).getValue();
        }
    };

Thread Participants: 1