Come aggiungere gli elementi della lista usando UiBinder?Come aggiungere elementi a GWT ListBox nel modello Uibinder .ui.xml?
risposta
Si tratta di una casella di riepilogo di traduzioni di un'enumerazione , Suppongo che questo funzioni anche per una listbox con valori stringa (versione di GWT: 2.1.0)
Tu serve solo il renderer per tradurre i valori di enumerazione.
// UI CODICE 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;
}
}
Dude ... fantastico codice sniplet ... Sei stato molto generoso. –
Gunnie, come sposeresti la tua soluzione con l'internazionalizzazione dichiarativa descritta [qui] (http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinderI18n.html)? – expert
E 'possibile da Febbraio 2011 versione:
http://code.google.com/p/google-web-toolkit/issues/detail?id=4654
seguito this patch si è ora in grado di aggiungere elementi seguente sintassi:
<g:ListBox>
<g:item value='1'>
first item
</g:item>
<g:item value='2'>
second item
</g:item>
</g:ListBox>
questo è ora in diretta btw – HaveAGuess
GWT ValueListbox altrimenti conosciuto come un ComboBox o di un componente a discesa. Un altro esempio che mostra anche la compilazione dell'elenco.
UiBinder ...
<g:ValueListBox ui:field="subCategory"/>
Editor ...
@UiField(provided = true)
ValueListBox<String> subCategory = new ValueListBox<String>(
new Renderer<String>() {
@Override
public String render(String object) {
String s = "Cats";
if (object != null) {
s = object.toString();
}
return s;
}
@Override
public void render(String object, Appendable appendable)
throws IOException {
render(object);
}
});
Constructor ...
List<String> values = new ArrayList<String>();
values.add("Animal Shelters and Rescues");
values.add("Birds");
values.add("Cats");
values.add("Dogs");
values.add("Other Pets");
values.add("Rabbits");
subCategory.setAcceptableValues(values);
- 1. Estendi il widget GWT creato utilizzando UIBinder
- 2. GWT: UiBinder o GWT Designer?
- 3. CellTables Definizione GWT con UiBinder
- 4. GWT 2.1 in UiBinder inserisce Cell Widgets
- 5. È possibile riutilizzare i pannelli GWT UIBinder?
- 6. FlowPanel vs. HTMLPanel in GWT UiBinder
- 7. Quale prodotto Google GWT utilizza UiBinder?
- 8. GWT - ListBox, come visualizzare l'anteprima di changeEvent
- 9. widget personalizzato gwt con configurazione di elementi figlio in UIBinder (come CustomButton)
- 10. Qual è il modo preferito per associare gli stili css ai widget GWT (usando UiBinder)?
- 11. Come posso impostare l'id per i widget GWT in UiBinder?
- 12. Posso usare i valori enum come valori di campo nel modello di UiBinder?
- 13. Come aggiungere/nel modello preg_replace
- 14. Come configurare flextable con uiBinder per GWT 2.4
- 15. Come posso aggiungere un oggetto a un ListBox?
- 16. GWT/UIBinder come trovare il file css principale con <ui:style>
- 17. GWT ListBox non selezionata di default
- 18. Utilizzare uibinder con SmartGWT?
- 19. Collegamento a elementi HTML in GWT
- 20. Istruzioni: UiBinder + GWT MVP + più aree di visualizzazione indipendenti
- 21. gwt uibinder ui: con - metodi di chiamata con argomenti
- 22. Come aggiungere elementi nel menu popup?
- 23. Impedire l'aggiunta di elementi duplicati a un ListBox
- 24. Come aggiungere file Jar esterno nel progetto GWT
- 25. Immagine nel pulsante GWT
- 26. Come aggiungere qualificatori const nel modello
- 27. Cambia stile UiBinder in un altro stile UiBinder Programmaticamente
- 28. Attributi personalizzati in UiBinder Widget
- 29. Come aggiungere elementi a DOMNodeList in PHP?
- 30. come aggiungere elementi a Spinner's ArrayAdapter?
http://code.google.com/webtoolkit/doc/ latest/DevGuideUiBinder.html # Hello_Widget_World mostra come aggiungere elementi ListBox dal file Java, anche se presumo che tu stia chiedendo se è possibile specificarli nel modello di UiBinder. – aem
sì .... sto chiedendo se siamo in grado di dare gli elementi nello stesso uibinder – Kasturi