PDA

View Full Version : grid with combobox



emmas
4 Feb 2010, 10:36 AM
Hi, I am trying to populate the combobox as a column of a grid by using result set from a stored procedure. I am getting errors when i run my application, after the grid get populated and when i click on column which supposed to be editable combobox:
java.lang.String cannot be cast to com.extjs.gxt.ui.client.data.ModelData

Here is all my code, I renamed the objects for simplicity -

1) ComboboxData class


publicclass ComboboxData extends BaseBeanModel{
private String comboboxDescription;
public String getComboboxDescription() {
return comboboxDescription;
}

publicvoid setComboboxDescription(String comboboxDescription) {
this.comboboxDescription = comboboxDescription;
}

}

2) GridData class


publicclassGridDataextends BaseBeanModel {

String reportDescription;
String assignedByUser;

public String getReportDescription() {
returnreportDescription;
}

publicvoid setReportDescription(String reportDescription) {
this.reportDescription = reportDescription;
}

public String getAssignedByUser() {
returnassignedByUser;
}

publicvoid setAssignedByUser(String assignedByUser) {
this.assignedByUser = assignedByUser;
}

}


3) and this is class to call procedures to populate grid and combobox with data

publicclass AccountManagementDao extends BaseDao {

public AccountManagementDao(HttpSession session) {
super(session);
}

// populate grid
public List<GridData> getGridDataList() {
ArrayList<GridData> list = new ArrayList<GridData>();
String procName = "sp_get_grid_data";

try {
DBProcedure dbProcedure = getDBProcedure(procName);
dbProcedure.execute();
ResultSet rs = dbProcedure.getResultSet();
while (rs.next()) {
GridData row = new GridData();
row.setReportDescription(rs.getString(1));
row.setAssignedByUser(rs.getString(2));

list.add(row);
}

} catch (Exception e) {
String stackTrace = ExceptionUtils.getStackTrace(e);
Log.error(stackTrace);
}
return list;
}

// populate combobox

public List<ComboboxData> getComboboxData () {
ArrayList<ComboboxData> list = new ArrayList<ComboboxData>();
String procName = "sp_get_combobox_data";
try {
DBProcedure dbProcedure = getDBProcedure(procName);
dbProcedure.execute();

ResultSet rs = dbProcedure.getResultSet();

while (rs.next()) {
ComboboxData row = new ComboboxData();
row.setCobmoboxDescription(rs.getString(1));
list.add(row);
}
} catch (Exception e) {
String stackTrace = ExceptionUtils.getStackTrace(e);
Log.error(stackTrace);
}
return list;
}


4) and here is the configuration part for the grid 2 columns:
//first column - editable combobox
ColumnConfig reportColumnConfig =new ColumnConfig("reportDescription", "Description", 300);
SimpleComboBox<ComboboxData> comboEditor = new SimpleComboBox<ComboboxData>();


ListStore<SimpleComboValue<ComboboxData>> comboStore = new ListStore<SimpleComboValue<ComboboxData>>(comboboxListLoader);
comboEditor.setStore(comboStore);
comboEditor.setEditable(false);


getResultColumnConfigs().add(reportColumnConfig);
reportColumnConfig.setEditor(new CellEditor(comboEditor));

comboEditor.setValueField("comboboxDescription");
comboEditor.setDisplayField("comboboxDescription");
comboEditor.setForceSelection(true);


//second column, normal, not editable
getResultColumnConfigs().add(new ColumnConfig("assignedByUser", "Assigned By User", 100));



Thank you

Arno.Nyhm
5 Feb 2010, 8:09 AM
[...]
But what i am asking is if you have a working example for grid with combobox where the data for both grid and combobox is coming from the stored procedure result sets.



you can start with this point...
http://www.extjs.com/examples/explorer.html#editablegrid

at first i would make it working with example data (coming from some store generated in your class) and if this all is working then i would switch to your beans / and or your store.

at first i would create models which extends BaseModelData

if this all works - then switch to fill the store with your data from DB.

i dont know it but i would look into your models and how they created.

i dont know why you make it as BaseBeanModel - i would create it from BaseModelData. and use the set("propertyname",value) and get("propertyname") in your setters and getters for your models.


maybe someone other has an idea where to look into.