PDA

View Full Version : comboBox.setTemplate(...)



soma13
1 Apr 2011, 1:29 AM
Hi All,

I would like to get a little help.

I want to use some javasctipt command in setTemplate() method because I need to convert my string values to a real filename:



ComboBox<Country> countryComboBox = new ComboBox<Country>();
countryComboBox.setStore(countryStore);
countryComboBox.setTemplate( getFlagTemplate("resources/images/flags") );
countryComboBox.setDisplayField("countryName");
...
[CODE]

[CODE]
private native String getFlagTemplate(String base)
/*-{
var flagImgName = {countryName}.toLowerCase();
return [
'<tpl for=".">',
'<div class="x-combo-list-item"><img width="16px" height="11px" src="' + base + flagImgName + '_small.png"></div>',
'</tpl>'
].join("");
}-*/;


Could you tell me how can I use {countryName}.toLowerCase() javascript method in getFlagTemplate() method?


thx!

bogusky
1 Apr 2011, 3:37 AM
ComboBox<Country> countryComboBox = new ComboBox<Country>();
countryComboBox.setStore(countryStore);
countryComboBox.setTemplate( getFlagTemplate("resources/images/flags") );
countryComboBox.setDisplayField("countryName");

countryComboBox.getView().setModelProcessor(new ModelProcessor<Country>() {

@Override
public Country prepareData(Country model) {
// format your value and set as temporary field
model.set("formated_value", model.getCountryName().toLowerCase());
return model;
}
});


template

private native String getFlagTemplate(String base)
/*-{
var flagImgName = {formated_value};
return [
'<tpl for=".">',
'<div class="x-combo-list-item"><img width="16px" height="11px" src="' + base + flagImgName + '_small.png"></div>',
'</tpl>'
].join("");
}-*/;

soma13
1 Apr 2011, 3:56 AM
I looked for this!

Thank you for your answer!