I'm trying to list a table inside a SelectItem component. I use for this purpose ListGrid component. Here is the code:
final ListGrid brandGrid = new ListGrid();
ListGridField nameField = new ListGridField("name");
ListGridField descriptionField = new ListGridField("description");
ListGridField detailField = new ListGridField("detail");
final SelectItem filterList = new SelectItem();
filterList.setDisplayField("name");
filterList.setValueField("description");
filterList.setPickListWidth(400);
filterList.setOptionDataSource(myDataSource);
filterList.setPickListFields(nameField, descriptionField);
filterList.setPickListProperties(brandGrid);
filterList.setDefaultValue(record.getAttributeAsString("name"));
filterList.setShowTitle(false);
filterList.setStartRow(false);
And the DataSource code for myDataSource instance (I call this method to initialize class attribute DataSource myDataSource
before I use SelectItem filterList
):
private DataSource getBrandData(List<BrandDB> result){
DataSource ds = new DataSource();
DataSourceTextField id = new DataSourceTextField();
id.setName("idBrand");
id.setPrimaryKey(true);
DataSourceTextField name = new DataSourceTextField();
name.setName("name");
DataSourceTextField description = new DataSourceTextField();
description.setName("description");
ds.setFields(id, nazov, popis);
ds.setClientOnly(true);
for(int i = 0; i < result.size(); i++){
Record rc = new Record();
rc.setAttribute("idBrand", result.get(i).getIdBrand()+"");
rc.setAttribute("name", result.get(i).getName());
rc.setAttribute("description", result.get(i).getDescription());
ds.addData(rc);
}
return ds;
}
The problem is that value description
in my datasource has in several places the same value (the id and name for these values is different). And I obtain following error:
TMR0:WARN:fetchMissingValues:isc_SelectItem_1:Deriving valueMap for 'description' from dataSource based on displayField 'name'. This dataSource contains more than one record with description set to Not defined with differing name values. Derived valueMap is therefore unpredictable.
Any ideas how to set the SelectItem to accept these duplicate values? Thank you very much for your answers. :)
Problem solved:
error is located in this line of code:
filterList.setValueField("description");
Description is not unique and because of this fact it cannot be value field inside the SelectItem component. It's necessary to edit only this line of code as follows:
filterList.setValueField("idBrand");
idBrand
is unique because it's defined as primary key in DataSource so SelectItem has uniquely identified its value fields and can make filters.