What is the best way to have a drop down comboboxitem or selectitem in Smartgwt?
Should I create listgridfields (Causes errors) or create DataSourceTextFields?
My usecase is to have an entity (e.g. for example city) that is categorized by type (e.g. country). This is a common use case for hibernate datasources where an object has a role or category.
An Employee may be assigned to a Job_type. Employee table has a Long fk_job_type_id. I want to update the employee's foreign key not the job type.
I have tried both (code is below). Neither seems to work....
It's hard to determine if I should use includeFrom or displayField; setForeignKey or setValueField, etc.
I would expect the foreignkey is ("country"). It's countryId.
Or something like
What is the best set of choices and what is the best example for code. The existing sample ones (databound comboboxes) do not cover this usecase well for the foreignkey.
Should I create listgridfields (Causes errors) or create DataSourceTextFields?
My usecase is to have an entity (e.g. for example city) that is categorized by type (e.g. country). This is a common use case for hibernate datasources where an object has a role or category.
An Employee may be assigned to a Job_type. Employee table has a Long fk_job_type_id. I want to update the employee's foreign key not the job type.
I have tried both (code is below). Neither seems to work....
It's hard to determine if I should use includeFrom or displayField; setForeignKey or setValueField, etc.
I would expect the foreignkey is ("country"). It's countryId.
Code:
package your.package.here; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.types.ListGridEditEvent; import com.smartgwt.client.util.KeyCallback; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.fields.ComboBoxItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.VLayout; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.Window; //import com.isomorphic.datasource.DataSource; public class MyDemo3b implements EntryPoint { DataSource hbdb; @Override public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); //CityManyToOneSimple a; // a.setCountry(new CountryManyToOneSimple().setCountryId(new Long(3L)); final ListGrid listGrid = new ListGrid(); // Window.alert("helloa"); // DataSource hbdb = new DataSource(); hbdb.setID("cityManyToOneSimpleHB"); listGrid.setDataSource(hbdb); listGrid.setWidth(700); // Window.alert("hellob"); listGrid.setHeight(224); listGrid.setShowFilterEditor(true); listGrid.setAlternateRecordStyles(true); listGrid.setAutoFetchData(true); listGrid.setDataPageSize(50); listGrid.setCanEdit(true); listGrid.setEditEvent(ListGridEditEvent.CLICK); listGrid.setCanRemoveRecords(true); ComboBoxItem cbxitem = new ComboBoxItem("country"); DataSource countryds = new DataSource(); countryds.setID("countryManyToOneSimpleHB"); cbxitem.setOptionDataSource(countryds);//countryds // DataSourceTextField lgfCountry = new DataSourceTextField("country", "Country"); ListGridField lgfCountry = new ListGridField("country", "Country"); ListGridField lgfcityid = new ListGridField("cityId"); lgfcityid.setHidden(true); // cbxitem.setValueField("country"); cbxitem.setDisplayField("countryName"); cbxitem.setAddUnknownValues(false); //cbxitem.setVa lgfCountry.setDisplayField("countryName"); lgfCountry.setEditorProperties(cbxitem); // lgfCountry.setForeignKey(foreignKey); // listGrid.setFields(new ListGridField("cityName", "City"), lgfCountry); listGrid.setFields(lgfcityid, new ListGridField("cityName", "City"), lgfCountry); IButton newButton = new IButton("Add New"); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); // Window.alert("helloc"); VLayout layout = new VLayout(); layout.setWidth100(); layout.addMember(listGrid); layout.addMember(newButton); layout.draw(); } }
Or something like
Code:
public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); //CityManyToOneSimple a; // a.setCountry(new CountryManyToOneSimple().setCountryId(new Long(3L)); final ListGrid listGrid = new ListGrid(); // Window.alert("helloa"); // DataSource hbdb = new DataSource(); hbdb.setID("cityManyToOneSimpleHB"); listGrid.setDataSource(hbdb); listGrid.setWidth(700); // Window.alert("hellob"); listGrid.setHeight(224); listGrid.setShowFilterEditor(true); listGrid.setAlternateRecordStyles(true); listGrid.setAutoFetchData(true); listGrid.setDataPageSize(50); listGrid.setCanEdit(true); listGrid.setEditEvent(ListGridEditEvent.CLICK); listGrid.setCanRemoveRecords(true); ComboBoxItem cbxitem = new ComboBoxItem("country"); DataSource countryds = new DataSource(); countryds.setID("countryManyToOneSimpleHB"); cbxitem.setOptionDataSource(countryds);//countryds // DataSourceTextField lgfCountry = new DataSourceTextField("country", "Country"); DataSourceTextField dsCountry = new DataSourceTextField("country", "Country"); //DataSourceIntegerField dscityid = new DataSourceIntegerField("cityId", "City Id"); DataSourceTextField dsCityName = new DataSourceTextField("cityName", "City"); // dscityid.setHidden(true); // cbxitem.setValueField("country"); cbxitem.setDisplayField("countryName"); cbxitem.setAddUnknownValues(false); //cbxitem.setVa dsCountry.setDisplayField("countryName"); dsCountry.setEditorProperties(cbxitem); dsCountry.setForeignKey("Country.country"); //dscityid, hbdb.setFields( dsCityName, dsCountry); // listGrid.setFields(new ListGridField("cityName", "City"), lgfCountry); // listGrid.setFields(dscityid, dsCityName, dsCountry); IButton newButton = new IButton("Add New"); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); // Window.alert("helloc"); VLayout layout = new VLayout(); layout.setWidth100(); layout.addMember(listGrid); layout.addMember(newButton); layout.draw(); } }
Comment