如何在 Uibinder .ui.xml 模板中向 GWT ListBox 添加项目? [英] How do I add items to GWT ListBox in Uibinder .ui.xml template ?
本文介绍了如何在 Uibinder .ui.xml 模板中向 GWT ListBox 添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 UiBinder 添加列表框项目?
How to add the listbox items using UiBinder?
推荐答案
这是一个枚举翻译的列表框,我想这也适用于带有字符串值的列表框(GWT 版本:2.1.0)
This is a listbox of translations of an enumeration, I suppose this also works for a listbox with string values (version of GWT: 2.1.0)
您只需要渲染器来翻译枚举值.
You only need the renderer for translating the enumeration values.
//UI XML
<g:ValueListBox ui:field="requesterType"/>
//Java代码
@UiField(provided = true)
ValueListBox<RequesterType> requesterType = new ValueListBox<RequesterType>(requesterTypeRenderer);
static EnumRenderer<RequesterType> requesterTypeRenderer = new EnumRenderer<RequesterType>();
public Constructor() {
requesterTypeRenderer.setEmptyValue(Translations.translateEmptyValue(RequesterType.class));
requesterType.setAcceptableValues(Arrays.asList(EnumUtil.getRequesterTypes()));
}
<小时>
/**
* Translates enum entries. Use setEmptyValue() if you want to have a custom empty value. Default empty value is "".
*
* @param <T>
* an enumeration entry which is to be registered in {@link Translations}
*/
public class EnumRenderer<T extends Enum<?>> extends AbstractRenderer<T> {
private String emptyValue = "";
@Override
public String render(T object) {
if (object == null)
return emptyValue;
return Translations.translate(object);
}
public void setEmptyValue(String emptyValue) {
this.emptyValue = emptyValue;
}
}
这篇关于如何在 Uibinder .ui.xml 模板中向 GWT ListBox 添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文