GXT - Pissed off with ComobBox in Grid (different Display Label and Value)
I am trying to add a CobmoBox in EditorGrid I have a class Vehicle with fields Integer vehicleId; String plateNo; Integer vehicleType; //1=Car,2=Truck
I want the combo box to show vehicle's type in text form i.e if vehicleType is 1, "Ca开发者_开发百科r" would be displayed. And when the user select any other option - like "Truck" the corresponding integer value should be populated into the bean.
This is pretty standard stuff with plain old JSP and HTML. However I couldn't find a simple way the do this in Ext GWT.
If you are using a GXT ComboBox, the easiest way to is create a model representing your vehicle object if you haven't already. This is basically a class that extends GXT's BaseModelData class.
Once you have your model, you create a combo box using that type:
ComboBox<VehicleModel> box = new ComboBox<VehicleModel>();
The last step is to tell the combo box which fields to use for values and for display, which is done with 2 method calls:
box.setDisplayField("field name for display");
box.setValueField("field name for value");
When you load up a store of vehicle models, GXT will take care of the rest. You will, however, need to convert the model back to the vehicle object itself to be persisted.
精彩评论