I am trying to have a form field contain one or more elements that are defined in a different data source. Elements have a numeric id and a human-readable name. It all works well until I try to save; in this case, I always get the "Not a valid option" error.
The form I am editing is based on a Campaigns datasource, that may be linked to zero or more Trunks.
Datasource Trunks are defined as:
DataSourceField fId = new DataSourceField(
"trunkId", FieldType.INTEGER, "Id");
fId.setPrimaryKey(Boolean.TRUE);
fId.setHidden(Boolean.TRUE);
fId.setCanEdit(Boolean.FALSE);
DataSourceField fName = new DataSourceField(
"trunkName", FieldType.TEXT, "Name");
fName.setRequired(Boolean.TRUE);
Datasource Campaigns have a field "trunk" defined as:
DataSourceField fTrunk = new DataSourceField(
"trunk",
FieldType.INTENUM,
"Trunk"
);
fTrunk.setMultiple(Boolean.TRUE);
fTrunk.setForeignKey("CfgTrunkDS.trunkId");
And here is the form definition to allow for multiple values being selected:
final DynamicForm form = new DynamicForm();
form.setIsGroup(true);
form.setGroupTitle("Update Campaign");
form.setNumCols(4);
form.setDataSource(dsCampaign);
form.setUseAllDataSourceFields(Boolean.TRUE);
final SelectItem selectItemMultipleGrid = new SelectItem("trunk");
selectItemMultipleGrid.setTitle("Trunk to use");
selectItemMultipleGrid.setMultiple(true);
selectItemMultipleGrid.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItemMultipleGrid.setOptionDataSource(CfgTrunkDS.getInstance());
selectItemMultipleGrid.setValueField("trunkId");
selectItemMultipleGrid.setDisplayField("trunkName");
form.setFields(selectItemMultipleGrid);
I also see the multiple values correctly and if I look at the "trunk" fiels, I see a string like "12, 16" when I select elements whose ids are 12 and 16. But still does not pass validation. I also noticed that if I comment the OptionDataSource in the form definition, it works just as fine.
What did I do wrong?