I try to use grid-form editor with rpc-datasource. The grid has address objects. The form has detail fileds of address and one field is ComboBoxItem with OptionDataSource (address-purpose objects).
But I don't know how to change values in ComboBoxItem. If I select record in grid, new row with purposeId add to comboBox, instead select one of item in comboBox.
DataSource of Address object:
DataSource of AddressPurpose object:
Source code of the grid-form panel:
But I don't know how to change values in ComboBoxItem. If I select record in grid, new row with purposeId add to comboBox, instead select one of item in comboBox.
DataSource of Address object:
Code:
public AddressDS(String id) { setID(id); DataSourceIntegerField idDF = new DataSourceIntegerField("id"); idDF.setPrimaryKey(true); idDF.setHidden(true); addField(idDF); DataSourceTextField nameDF = new DataSourceTextField("name", "Name"); addField(nameDF); DataSourceTextField descriptionDF = new DataSourceTextField("description", "Description"); addField(descriptionDF); DataSourceIntegerField purposeId = new DataSourceIntegerField("purposeId"); purposeId.setHidden(true); addField(purposeId); DataSourceTextField purposeName = new DataSourceTextField("purposeName", "Purpose"); addField(purposeName); }
Code:
public AddressPurposeDS(String id) { setID(id); DataSourceIntegerField purposeId = new DataSourceIntegerField("purposeId"); purposeId .setPrimaryKey(true); addField(purposeId); DataSourceTextField purposeName = new DataSourceTextField("purposeName"); addField(purposeName); }
Code:
final AddressDS ds = AddressDS.getInstance(); final ListGrid grid = new ListGrid(); grid.setDataSource(ds); grid.setAlternateRecordStyles(true); grid.setShowAllRecords(true); grid.setAutoFetchData(true); grid.setCanEdit(false); grid.setCanResizeFields(true); final DynamicForm form = new DynamicForm(); form.setDataSource(ds); final ComboBoxItem purpose = new ComboBoxItem(); purpose.setOptionDataSource(AddressPurposeDS.getInstance()); purpose.setName("purposeId"); purpose.setValueField("purposeId"); purpose.setDisplayField("purposeName"); purpose.setAutoFetchData(true); TextItem name = new TextItem("name"); form.setFields(purpose, name); grid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() { public void onRecordDoubleClick(RecordDoubleClickEvent event) { form.clearErrors(true); form.editRecord(event.getRecord()); } });
Comment