1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Question Help with ClassCastException / CellEditor / ComboBox / RowEditor

    Help with ClassCastException / CellEditor / ComboBox / RowEditor


    I have a BeanModel grid with a RowEditor. One of the columns is a CellEditor with a ComboBox. When I press revise (i.e. call startEditing of the roweditor) a ClassCastException is thrown:

    Uncaught exception escaped
    java.lang.ClassCastException: java.lang.String
    at com.extjs.gxt.ui.client.widget.form.ComboBox.setValue(ComboBox.java:1)
    at com.extjs.gxt.ui.client.widget.grid.RowEditor.startEditing(RowEditor.java:436)
    at de.test.client.TestTable.reviseRow(TestTable.java:160)
    ...

    Consequently the roweditor crashes and displays an empty line instead of editing the existing line.

    error.png

    Can you give me a hint about the cause of this problem? I have no idea, I'm stuck here

    Below are the most important three classes, the full code is in the attachment. Thank you in advance for any help

    GenericDropdownCombobox.java:
    Code:
    package de.test.client;
    
    import java.util.List;
    
    import com.extjs.gxt.ui.client.data.BaseListLoader;
    import com.extjs.gxt.ui.client.data.ListLoadResult;
    import com.extjs.gxt.ui.client.data.ModelData;
    import com.extjs.gxt.ui.client.data.RpcProxy;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
    import com.extjs.gxt.ui.client.widget.form.SimpleComboValue;
    import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
    import com.extjs.gxt.ui.client.widget.grid.CellEditor;
    
    import de.ec4u.c4.servermanager.gwt.util.DropdownDto;
    
    
    public class GenericDropdownCombobox {
    
        public static CellEditor createComboBoxEditor(String fieldLabel,
                String emptyText,
                RpcProxy<List<String>> rpcProxy) {
            return new CellEditor(createComboBox(fieldLabel, emptyText, rpcProxy));
        }
    
        public static CellEditor createCellEditor(final SimpleComboBox<String> combo) {
            return new CellEditor(combo) {
                @Override
                public Object preProcessValue(Object value) {
                    if (value == null) {
                        return value;
                    }
                    return combo.getStore().findModel("name", value.toString());
                }
    
                @Override
                public Object postProcessValue(Object value) {
                    if (value == null) {
                        return value;
                    }
                    return ((ModelData) value).get("name");
                }
            };
        }
    
        public static SimpleComboBox<String> createComboBox(String fieldLabel,
                String emptyText,
                RpcProxy<List<String>> proxy) {
            return createComboBox(fieldLabel, emptyText,
                    new ListStore<SimpleComboValue<String>>(
                            new BaseListLoader<ListLoadResult<String>>(proxy)));
        }
    
        public static SimpleComboBox<String> createComboBox(String fieldLabel,
                String emptyText, ListStore<SimpleComboValue<String>> store) {
            final SimpleComboBox<String> combo = new SimpleComboBox<String>();
           combo.setForceSelection(true);
           combo.setTriggerAction(TriggerAction.ALL);
           combo.setStore(store);
    
            return combo;
        }
    }
    TestDto.java
    Code:
    package de.test.client;
    
    import java.io.Serializable;
    
    import com.extjs.gxt.ui.client.data.BeanModel;
    import com.extjs.gxt.ui.client.data.BeanModelTag;
    
    public class TestDto implements BeanModelTag, Serializable {
    
        private static final long serialVersionUID = -6372593622124984707L;
        
        public static final String TEST_NAME = "name";
        public static final String TEST_SYSTEM = "system";
    
        private String name;
        private String system;
        
        public TestDto() {
    
        }
    
        public TestDto(String name, String system) {
            this.name = name;
            this.system = system;
        }
    
        public String getSystem() {
            return system;
        }
    
        public void setSystem(String system) {
            this.system = system;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
    
        public static TestDto convertToTestDto(BeanModel bm) {
            TestDto dto = new TestDto();
    
            dto.setName((String) bm.get(TEST_NAME));
            dto.setSystem((String) bm.get(TEST_SYSTEM));
    
            return dto;
        }
    
    }
    TestTable.java
    Code:
    package de.test.client;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import com.extjs.gxt.ui.client.Style.SelectionMode;
    import com.extjs.gxt.ui.client.data.BasePagingLoader;
    import com.extjs.gxt.ui.client.data.BeanModel;
    import com.extjs.gxt.ui.client.data.BeanModelReader;
    import com.extjs.gxt.ui.client.data.ModelData;
    import com.extjs.gxt.ui.client.data.PagingLoadConfig;
    import com.extjs.gxt.ui.client.data.PagingLoadResult;
    import com.extjs.gxt.ui.client.data.RpcProxy;
    import com.extjs.gxt.ui.client.event.Events;
    import com.extjs.gxt.ui.client.event.GridEvent;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.widget.Composite;
    import com.extjs.gxt.ui.client.widget.LayoutContainer;
    import com.extjs.gxt.ui.client.widget.form.TextField;
    import com.extjs.gxt.ui.client.widget.grid.CellEditor;
    import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
    import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
    import com.extjs.gxt.ui.client.widget.grid.Grid;
    import com.extjs.gxt.ui.client.widget.grid.RowEditor;
    import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    
    
    class TestTable extends Composite {
    
        private Grid<BeanModel> gridTest;
    
        public static int LOADROWS = 20;
        private static final int COLUMN_WIDTH = 142;
        private Map<String, String> columns = new HashMap<String, String>();
        
        public List<ColumnConfig> createConfigs() {
    
            columns.put(TestDto.TEST_NAME, "Id");
            columns.put(TestDto.TEST_SYSTEM, "System");
    
            List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
            for (Map.Entry<String, String> column : columns.entrySet()) {
                configs.add(new ColumnConfig(column.getKey(), column.getValue(),
                        COLUMN_WIDTH));
            }
            return configs;
        }
    
        final RowEditor<BeanModel> rowEditor = new RowEditor<BeanModel>() {
            public void stopEditing(boolean saveChanges) {
                super.stopEditing(saveChanges);
                gridTest.enableEvents(true);
                disable();
            };
        };
    
        private RpcProxy<PagingLoadResult<TestDto>> proxy = new RpcProxy<PagingLoadResult<TestDto>>() {
    
            @Override
            public void load(Object loadConfig,
                    AsyncCallback<PagingLoadResult<TestDto>> callback) {
                TestGridService.Util.getInstance().loadPage(
                        (PagingLoadConfig) loadConfig, callback);
            }
        };
    
        private final BasePagingLoader<PagingLoadResult<ModelData>> testLoader = new BasePagingLoader<PagingLoadResult<ModelData>>(
                proxy, new BeanModelReader());
    
        public TestTable(String testImpl) {
    
            LayoutContainer layoutContainer = new LayoutContainer();
            layoutContainer.setHScrollPosition(690);
    
            ListStore<BeanModel> testDtos = new ListStore<BeanModel>(testLoader);
    
            final PagingToolBar pagingToolBar = new PagingToolBar(LOADROWS);
            testLoader.setRemoteSort(true);
    
            pagingToolBar.bind(testLoader);
    
            gridTest = new Grid<BeanModel>(testDtos, new ColumnModel(
                    setEditor(createConfigs())));
            gridTest.enable();
            gridTest.setHeight(250);
            gridTest.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    
            rowEditor.disable();
            gridTest.addPlugin(rowEditor);
    
            gridTest.addListener(Events.Attach, createGridAttachListener());
    
            gridTest.setLoadMask(true);
            gridTest.setHeight(300);
            gridTest.setWidth(500);
            gridTest.setBorders(true);
            gridTest.setStripeRows(true);
    
            layoutContainer.add(gridTest);
            layoutContainer.add(pagingToolBar);
            layoutContainer.setBorders(true);
            initComponent(layoutContainer);
        }
    
        private Listener<GridEvent<BeanModel>> createGridAttachListener() {
            return new Listener<GridEvent<BeanModel>>() {
                public void handleEvent(GridEvent<BeanModel> bme) {
                    testLoader.load(0, LOADROWS);
                }
            };
        }
    
        private List<ColumnConfig> setEditor(List<ColumnConfig> cols) {
    
            for (ColumnConfig config : cols) {
                if (config.getId().equals(TestDto.TEST_NAME)) {
                    TextField<String> tf = new TextField<String>();
                    CellEditor ce = new CellEditor(tf);
                    tf.setAllowBlank(false);
                    ce.setEnabled(true);
                    ce.setVisible(true);
                    config.setEditor(ce);
                } else if (config.getId().equals(TestDto.TEST_SYSTEM)) {
                    config.setEditor(createTestSystemComboBoxEditor());
                }
            }
            return cols;
        }
    
        Grid<BeanModel> getGrid() {
            return gridTest;
        }
    
        private CellEditor createTestSystemComboBoxEditor() {
            return GenericDropdownCombobox.createComboBoxEditor("name",
                    "Select a system...", new RpcProxy<List<String>>() {
    
                        @Override
                        protected void load(Object loadConfig,
                                AsyncCallback<List<String>> callback) {
                            IntegrationDropdownStoreService.Util.getInstance()
                                    .getSystemsDropdown(callback);
    
                        }
                    });
        }
    
        protected void reviseRow() {
            BeanModel select = gridTest.getSelectionModel().getSelectedItem();
            rowEditor.enable();
            rowEditor.startEditing(gridTest.getStore().indexOf(select), true);
            gridTest.disableEvents(true);
        }
    
    }
    Attached Files

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You normally dont set an own store on a SimpleComboBox. You simple add the strings there manually. Thats the first issue. Second, your CellEditor references a dataindex "name", but in SimpleComboValue its called "value".

    Take a look at this example: http://www.sencha.com/examples/explo...#roweditorgrid

    Its exactly doing what you are trying to do.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Default


    I've tried both of your proposals but it still doesn't work.

    The difference to the example is that it is a grid based on ModelData instead of BeanModelTag. Could that be an issue?

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    No that is not the problem. BeanModelTag gets transformed to a ModelData using a factory internly (the BeanModelReader in your case).

  5. #5
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Default


    Mmmh... so when working with a SimpleComboBox without the store/rpcproxy, I would need to add a listener (which one?) to the SimpleComboBox and then make a server call to get a list of strings and then fill them in with add?

    The strange thing is that I had it working with ComboBoxes and Stores once... somehow it doesn't work anymore and I have absolutely no clue why it throws those ClassCastExceptions... When trying to add a line and saving it the same problem occurs. It seems to have problems converting between String and my BeanModel Dto class...

    Ok, I've got it working by reverting partly to an earlier revision. I'll post the reason as soon as I've investigated, maybe it helps some other poor guy

  6. #6
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Default


    Ok, the error was in the preProcessValue function. It needs to return a string, not a model.

    With that working I'm still facing the problem with the RPC call. I call startEditing of RowEditor which activates the CellEditor. As far as I see a cell editor with a DropDown element with a RpcProxy as Liststore still has an empty store when preProcessValue is called (i.e. the RPC call is still running). This results in the preProcessValue function always returning null.

    Has anyone a suggestion on how to finish the RPC call *before* the preProcessValue function without relying on an ugly mess of chained, manual Rpc calls?

  7. #7
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Has anyone a suggestion on how to finish the RPC call *before* the preProcessValue function without relying on an ugly mess of chained, manual Rpc calls?
    Listen to the BeforeEdit event of the RowEditor and if that fires and the store is still empty, cancel that event and mask the screen. Once the store got loaded. Unmask the screen and manually start editing of that row. This would be one approach

  8. #8
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Default


    Ah, that sounds like a good idea, thank you

    Edit:
    Ok, two questions remain:

    If I cancel the StartEditing call by listening to BeforeEdit how will the RpcListStore ever get the event to load the data? Or does a startEditing call on the EVER call the RpcListStore? Judging from the behavior of the program the store is *only* filled when I click on the dropdown button (the loading animation occurs and there is a web service call).
    So I would have to fire the RPC manually.

    This leads to the second question: How do I access the store in the BeforeEdit Listener? I wonder because it is the row editor that creates the dropdown in the first place (with information from the columnconfig). So I can't check the store before it is created, but when it is created it is too late because the roweditor already wants to select a value from the store of the dropdown.

    Oh dear :o

  9. #9
    Sencha User
    Join Date
    Oct 2010
    Posts
    20
    Vote Rating
    0
    Clemensl is on a distinguished road

      0  

    Default


    Ok, I just started to attack this issue again

    I've tried using this Listener, but it is just a draft, it is not working. I'm certainly missing something here.
    I determine the store and if it is empty then call the load procedure, mask the screen and add a listener to unmask and recall the roweditor.

    Do you have any additional hint? Thank you in advance

    PHP Code:
        private Listener<RowEditorEvent> createBeforeEditListener() {
            return new Listener<RowEditorEvent>() {
                public void handleEvent(RowEditorEvent be) {
                    boolean cancel = false;
                    List<ColumnConfig> columns = grid.getColumnModel().getColumns();
                    for (ColumnConfig columnConfig : columns) {
                        CellEditor cellEditor = columnConfig.getEditor();
                        if (cellEditor != null) {
                            Field field = cellEditor.getField();
                            if (field != null && field instanceof ComboBox<?>) {
                                
    ComboBox<DropdownDtocomboBox = (ComboBox<DropdownDto>) field;
                                
    ListStore listStore comboBox.getStore();
                                if (
    listStore.getCount() == 0
                                        
    && !listStore.hasActiveEvent()) {
                                    
    listStore.getLoader().load();
                                    if (!
    cancel) {
                                        
    cancel true;
                                        
    listStore.addListener(Store.DataChanged,
                                                
    createStoreDataChangedListener());
                                    }
                                }
                            }
                        }
                    }
                    if (
    cancel) {
                        
    grid.mask();
                        
    be.setCancelled(true);
                    }
                }
            };
        }

        private 
    Listener<BaseEventcreateStoreDataChangedListener() {
            return new 
    Listener<BaseEvent>() {
                public 
    void handleEvent(BaseEvent be) {
                    
    grid.unmask();
                    
    reviseRow();
                }
            };
        }
        
        public 
    void reviseRow() {
            
    buttonBar.resetAdded();

            
    BeanModel select grid.getSelectionModel().getSelectedItem();
            
    rowEditor.enable();
            
    rowEditor.startEditing(grid.getStore().indexOf(select), true);
            
    disableGridEvents();
        }

Similar Threads

  1. ClassCastException with combobox
    By ruperty in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 31 Oct 2010, 7:00 AM
  2. Combobox in the CellEditor
    By Jenya in forum Ext GWT: Discussion
    Replies: 1
    Last Post: 23 Aug 2010, 1:23 AM
  3. CellEditor: ComboBox (different selections per row)
    By paco_online in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 30 Apr 2010, 8:35 AM
  4. [CLOSED] Combobox - ClassCastException
    By fother in forum Ext GWT: Bugs (1.x)
    Replies: 1
    Last Post: 25 Nov 2008, 9:32 AM

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar