PDA

View Full Version : [CLOSED] Binding ComboBox with RpcProxied Store



ashleywong
11 Jun 2008, 10:35 PM
I can find TableBinder, DataListBinder and TreeBinder. Will there be ComboBoxBinder?

I am tried to use RpcProxy for loading data to the ComboBox's store. But I cannot load the data to the ComboBox. Does the binder class do the job for binding the result to the component?

Thank you.

assassin
12 Jun 2008, 1:15 AM
Hi,

A binder on a ComboBox is not needed because the values in the ComboBox are not editable. Use the following code to load data trough an RpcProxy.



// data proxy
// Edit BaseModel to your own Model type
RpcProxy<BaseModel, List<BaseModel>> proxy = new RpcProxy<BaseModel, List<BaseModel>>() {
@Override
protected void load(BaseModel loadConfig,
AsyncCallback<List<BaseModel>> callback) {
service.getChildFolders(loadConfig, callback);
}
};

// list loader
final ListLoader<BaseModel> loader = new BaseListLoader(proxy);
//store
ListStore store = new ListStore(loader);

//add store to combobox

loader.load(null);

ashleywong
12 Jun 2008, 2:31 AM
Thanks

Grandiosa
12 Jun 2008, 10:45 AM
I don't think that code will compile, ListLoader is declared as:

Interface ListLoader<C extends ListLoadConfig>


So you can't type the loader using a Model object. I tried this approach as well as it would make sense when you're calling the load method with a plan Model object as the configuration parameter.

When I calll the Loader.load() method I specify a Model object as a parameter, not a config object. This is perfectly valid and makes very much sense in situations where your Model object is lazily constructed, for example based on a selection in another combobox. The rpc proxy will just use that model object as a parameter to the RPC call.

But as things works now you will have to write it like this:

ListLoader loader = new BaseListLoader(proxy) ;

assassin
13 Jun 2008, 12:23 AM
You are wright you can also solve the problem by implementing the ListLoadConfig interface into your own extended basemodel class.

Branco
21 Jan 2009, 8:09 AM
Hi,

A binder on a ComboBox is not needed because the values in the ComboBox are not editable.


Not needed?

Then get this example... which is giving me an headache:

I have a grid with several records. When i click one of them, a form is updated via formBinding, to show the data of that selected row. All working with RPC. All fine.

All but... comboboxes. I use FieldBinding in TextField, NumberField, DateField... Can't do it in combobox.

I want my combobox, which is populated with a .setStore(myMethodThatLoadsAStoreViaRpcANDWORKS) to display the correct entry when i select the row in the grid.

My bean, which I pass on formBinding, has attributes of type String and Integer, which I bind directly to FieldText, and of type Date, which I bind directly to DateField. No problems.

But i also have foreign keys on my table, which hold the ID of the entry to select from the combobox. Let's think COUNTRY. I don't want to pass the value "Portugal" or "France", i want to pass the ID in table Country that corresponds to the value "Portugal" or "France". I don't want to set RawValues....

I want to be able to type:


formBinding.addFieldBinding(new FieldBinding(myComboBox, "countryId"));where countryId is normal for my bean to do:


myBean.get("countryId");just like he does when i type

formBinding.addFieldBinding(new FieldBinding(myCountryNameTextField, "countryName"));I've read these posts, to no avail...

http://extjs.net/forum/showthread.php?t=54769

https://yui-ext.com/forum/showthread.php?t=56855

What do the experts suggest I do here?

gslender
22 Jan 2009, 2:37 AM
For static lists of items I use an Enum in your POJO and use SimpleCombo to display the value - ensure a toString is included in the Enum and it works fine.

Branco
22 Jan 2009, 3:02 AM
Thanks again gslender for your help and interest.

Could you please explain it better?

Where do i use the enum? In my pojo? But I dont want an enum, i want a single ID.

like my Boat class has a hull type, a color, etc.

So when i select a specific boat from my grid, i want it to bind it's data to a form which has combos for hull type and color. I would like the formBinding to automatically select the correct entry in the combo.

It makes no sense for my bean to have an enum, when that specific bean (that specific boat), only has ONE hull type and ONE color. I have only a long with hullTypeId and colorId.

My other solution would be to have:


public class Boat4GWT implements BeanModelTag, Serializable{

private Hull4GWT hull;
private Color4GWT color;
}

But i also don't know how i will bind it to the combo.

I've been looking into the GXT API and maybe, just maybe StoreBinder will work for me...
StoreBinder has a setSelection(Model selection) method, that migth just do the trick...

Since my combo has a ListStore of, let's say, Color4GWT... if I use the StoreBinder for that comboBox and use storeBinder.setSelection(boat.getColor()), will it work?

boat.getColor() returns a Color4GWT object, so it should work, no?

Or do you have any other suggestions? (with code if possible:>)

gslender
22 Jan 2009, 1:55 PM
I use this...


public enum FreqType {
DAILY("Daily"), WEEKLY("Weekly"), FORTNIGHTLY("Fortnightly"), MONTHLY("Monthly"), QUARTERLY("Quarterly"), YEARLY("Yearly");

private String name;

FreqType(String name) {
this.name = name;
}

public String toString() {
return name;
}
}

and then I use this in SimpleCombo and POJO like...



freqTypeFld = new SimpleComboBox<FreqType>();
freqTypeFld.setFieldLabel("Frequency");
freqTypeFld.add(Arrays.asList(FreqType.values()));
freqTypeFld.setEmptyText("Choose...");
freqTypeFld.setEditable(false);
freqTypeFld.setAllowBlank(false);

....

freqTypeFld.setSimpleValue(mypojo.getFreq());

Branco
23 Jan 2009, 3:11 AM
Solved!

It's similar to what i have, but i still use ComboBox instead of SImpleComboBox.

That thing i did was in my Model analysis. Instead of having fields of type long to hold the Id of the Hull and of the Color, i am now using:


private Color color;
private Hull hull;

and then just do:


myColorCombo.setRawValue(boat.getColor().getDesciption());
myColorCombo.setValue(boat.getColor());

This way the Bean is set (via setValue() and I can get it when i want to save it later with getValue()) and ALSO the correct text appears on the combo, via setRawValue().

Nice. ~o)

By the way, I'm not using formBinding anymore. Prefer to set and get the values on my own. Things like boat.getRecord().getActivity().getDescription() don't work well. You have to make a converter or such other thing. It's so much easier with .setValue(get().get()...).

sufiya
23 Jan 2009, 4:36 AM
Branco,

I am also using enum for my ComboBox list instead of SImpleComboBox but unable to make it work

can you please send me how you have implimented ( may be sample code)

My code..

enum AutoSupportEnabled {
YES("Yes"),
No("No");
private String name;
AutoSupportEnabled(String name) {
this.name = name;
}
public String toString() {
return name;
}
}

ComboBox<AutoSupportEnabled > combo = new ComboBox<AutoSupportEnabled >();//i get error in this line doesn't recognise AutoSupportEnabled
combo1.setValue(AutoSupportEnabled.values()); //error-uncheckvalue to sertValue(D)

I tried using setRawValue no luck

Branco
23 Jan 2009, 5:36 AM
I don't use Enums that much, so I can't help you there.

But... what I did is instead of the Enum, your AutoSupport is a class:


public class AutoSupport{

private String id;
private String desc;

...getters and setter...

}Your combo, to get loaded from an existint user who has AutoSupport is like this:


AutoSupport as = new AutoSupport();
as.setId(1);
as.setDesc("YES");

ComboBox combo = new ComboBox();
combo.setValue(as); //this line binds the "bean" to the combo, so you later can do (1)
combo.setRawValue(as.getDesc()); //this "types" a string in the combo, since setValue is not enough for the user's "eyes"Of course this is an example... i'm getting my values from DB via RPC proxy... so I just do:



combo.setValue(user.getAutoSupport());
combo.setRawValue(user.getAutoSupport().getDesc());
(1): to get the value from the combo, for example to save the form:


AutoSupport userSelectedAutoSupport = (AutoSupport)combo.getValue();

Hope it helps, or at least gives you an hint on how to do it...