I never worked with hibernate, but your general use case seems pretty usual. CRUD ListGrid with FKs. And obviously at no time you want to see IDs, but always some text from the child table.
So here my observations: ListGrid has two states:
- Showing data
- Editing one row
For state one everything can be handled with .ds.xml files.
Code:
<field name="RESELLER_ID" foreignKey="T_RESELLER.ID" joinType="outer" displayField="RESELLER_NAME" type="integer" /> <field name="RESELLER_NAME" includeFrom="T_RESELLER.NAME"></field>
You'll want to use setOptionDataSource(ParentDS), setValueField("ID"), setDisplayField("NAME") in your editor item.
Once you got that working you can play with the *PickList*-methods in your ListGridField's SelectItem.
Code:
lgf.setEditorProperties(new ComboBoxItemCountry (...));
Some Editorclass of mine:
public class ComboBoxItemCountry extends ComboBoxItem {
final private DataSource countryDS = DataSource.get(DatasourceEnum.T_COUNTRY.getValue());
public ComboBoxItemCountry(String name, boolean showTelephone) {
super(name);
setOptionDataSource(countryDS);
setValueField(countryDS.getPrimaryKeyFieldName());
setFetchMissingValues(true);
ListGridField shortnameDeLGF;
if (showTelephone) {
setOptionOperationId("fetchDropdowndataTelephone");
setDisplayField("SHORTNAME_DE_CCPLUS");
setSortField("SHORTNAME_DE_CCPLUS");
//setDefaultValue("Deutschland (+49)");
setDefaultValue(246); //Deutschland
shortnameDeLGF = new ListGridField("SHORTNAME_DE_CCPLUS");
} else {
setOptionOperationId("fetchDropdowndataCountry");
setDisplayField("SHORTNAME_DE");
setSortField("SHORTNAME_DE");
//setDefaultValue("Deutschland");
setDefaultValue(37); //Deutschland
shortnameDeLGF = new ListGridField("SHORTNAME_DE");
}
setValidateOnExit(true);
setDefaultToFirstOption(true);
setTextMatchStyle(TextMatchStyle.SUBSTRING);
setBrowserSpellCheck(false);
//in ds.xml without escapeHTML!
ListGridField countrycodeLGF = new ListGridField("ISO_3166_1_ALPHA_2", "Flag", 25) {
{
setAlign(Alignment.CENTER);
setType(ListGridFieldType.IMAGE);
setImageURLPrefix("flags/16/");
setImageURLSuffix(".png");
}
};
setPickListFields(countrycodeLGF, shortnameDeLGF);
setPickListHeaderHeight(0);
setPickListWidth(200);
setPickListHeight(200);
}
}
Best regards,
Blama
Leave a comment: