Home‎ > ‎UI‎ > ‎

ValueListBox



This is how I use a ValueListBox to render items for selection inside of Editors.


ValueListBox<Intereger> use in an Editor

  @UiField(provided = true) 
 
ValueListBox<Integer> semester = new ValueListBox<Integer>(new Renderer<Integer>() {
   
public String render(Integer object) {
     
String s = "";
     
if (object != null) {
        s
= object.toString();
     
}
     
return s;
   
}
   
public void render(Integer object, Appendable appendable) throws IOException {
       
String s = render(object);
        appendable
.append(s);
   
}
 
});
   Other settings you can use with renderer:
    semester.setAcceptableValues(Arrays.asList(1,2));
    semester
.setValue(1);

ValueListBox<Integer> & Using Enum for Selections

This is how I render my selections form an Enum.
  @UiField(provided = true) 
 
ValueListBox<Integer> gender = new ValueListBox<Integer>(new Renderer<Integer>() {
   
public String render(Integer object) {
     
return Gender.getGenderName(object);
   
}
   
public void render(Integer object, Appendable appendable) throws IOException {
     
String s = render(object);
      appendable
.append(s);
   
}
 
});
public enum Gender {
  MALE
(1),
  FEMALE
(2);

 
int gender;

 
Gender(int gender) {
   
this.gender = gender;
 
}

 
public int getGender() {
   
return gender;
 
}

 
public String toString() {
   
return name();
 
}
 
 
public static ArrayList<Integer> getValues() {
   
Gender[] values = Gender.values();
   
ArrayList<Integer> list = new ArrayList<Integer>();
   
for (int i=0; i < values.length; i++) {
      list
.add(values[i].getGender());
   
}
   
return list;
 
}
 
 
public static String getGenderName(Integer gender) {
   
if (gender == null) {
     
return "";
   
}
   
String s = "";
   
switch (gender) {
   
case 1:
      s
= "male";
     
break;
   
case 2:
      s
= "female";
     
break;
   
}
   
return s;
 
}
}





Comments