I want to be able to render a Grid while the number of some extra columns are unknown until I’m in the onRender() method based on the type of a certain data.
I have this class
ActivityModel extends BaseDataModel {
// defines all common setXXX and getXXX needed
}
my problem is that, coming back from the server side, the model carries also some extra fields which must be also rendered as columns within the Grid.
My question :
Is there a way to have a kind of Indexed fields within AcitivityModel to be able to do the following ? : focus on col.setId("{indexed}");
List<ActivityParameterModel> parameters = folderModel.getParameters();
for (ActivityParameterModel param : parameters) {
ActivityParamType paramType = param.getParamType();
col = new ColumnConfig();
col.setHeader(param.getParamName());
col.setWidth(2);
//
// the following line is what I'm expecting to do
col.setId("{indexed}");
switch (paramType) {
case N:
NumberField nf = new NumberField();
nf.setPropertyEditorType(Integer.class);
col.setEditor(new CellEditor(nf));
break;
case S:
TextField<String> tf = new TextField<String>();
col.setEditor(new CellEditor(tf));
break;
}
config.add(col);
here’s what I did to come up with the situation :
I stored in DB the variable parameters, here’s the entity :
at creation time of the grid, I created the fixed columns then I made a loop to build the variable parameters using simply set(paramName,DEFAULT_VALUE) as following :
it creates the extra columns and at submit time, I restore the values by looping again over parameter list and calling the get(paramName) to restore the value.