I have a SelectItem (with setMultiple(true)) that is part of a DynamicForm that is bound to a DataSource that talks to a Grails REST Controller. I think I read some posts that there are some problems with a databoiund multiple-select SelectItem, so I am actually using a separate ListGrid for the UI and then it populates the SelectItem in the form like so:
groupsGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
public void onSelectionChanged(SelectionEvent event) {
ArrayList<String> selectedIdList = new ArrayList<String>();
for(ListGridRecord record : groupsGrid.getSelection()) {
selectedIdList.add(record.getAttributeAsString("id"));
}
groupsItem.setDefaultValues(selectedIdList.toArray(new String[selectedIdList.size()]));
}
});
The strange thing is that when the SelectItem is properly bound using setValueXPath, I can’t seem to update the values using setDefaultValues. Here is the DataSource:
DataSourceIntegerField userGroupsField = new DataSourceIntegerField("groups", "User Groups");
userGroupsField.setMultiple(true);
userGroupsField.setValueXPath("groups/id");
userGroupsField.setForeignKey("userGroup.id");
It also does not work if I remove the setValueXPath altogether. However, if I setValueXPath to anything else, setDefaultValues works and I am also able to perform successful updates to the server. Here is an example:
DataSourceIntegerField userGroupsField = new DataSourceIntegerField("groups", "User Groups");
userGroupsField.setMultiple(true);
userGroupsField.setValueXPath("nonsense/id");
userGroupsField.setForeignKey("userGroup.id");
Just curious why this is happening (because it cost me a bit of time and I’m not really satisfied with the resolution) and if there would be a better way to do what I need to do?