Search code examples
javauser-interfacegxt

CellEditor SimpleComboBox<BeanModel> save data to store


The final solution looked something like this:

grid.addListener(Events.AfterEdit, new Listener<GridEvent<BeanModel>>() {
    @Override
    public void handleEvent(GridEvent<BeanModel> be) {
        try{
             // get column where combo box is, in this case, column 2
             if (be.getColIndex == 2) {
                  BeanModel m = be.getModel();
                  DataObjectInStore data = be.getBean();
                  // convert bean model to object if needed before saving to data
                  ValueObject v = (ValueObject) be.getValue();
                  data.setComboValue(v);
}

==================================================================================

I've created a CellEditor that is a SimpleComboBox object. It looks like it works fine, yet I seem to be missing a step when I do a grid.getStore().getModels() and retrieve the data. The selected value from the combo box does not save to the store. How would I get it to save to the store properly?

The grid itself is pretty complex. I'll try to provide a simplified version that does the same.

editor = new CellEditor(comboBox) {
@Override 
public Object preProcessValue(Object value) {  
   if (value == null) {  
     return  null;  
}  
return comboBox.findModel(null);  
 }  

  @Override  
  public Object postProcessValue(Object value) {  
    if (value == null) {  
      return null;  
    }  
    SimpleComboBox<BeanModel> bean = (SimpleComboBox<BeanModel>) value;
      return bean.getValue().getBean();
}  
};  

configs.setEditor(editor) // configs = ColumnConfig

cm = new ColumnModel(configs);
grid = new Grid<BeanModel>(cm, store);

The store for the grid is a BeanModel of a GridDataObject with variables like strings and a dataObject. The comboBox is a collection of BeanModel of the dataObject. The dataObject has values that contain an id and stringvalue that identify the entry in the database.

Thanks in advance.


Solution

  • The problem I had was that when the drop down finished editing, it wasn't reading the value right because it was an object within a beanmodel, so I had to add a gridevent listener that would check each time it finished editing and set the right value at that time.