Pages

Friday, March 7, 2014

Vaadin ComboBox inner class bean

Using an inner-class with default (no modifier) access fails when used as a bean in a Vaadin ComboBox with:


Caused by: java.lang.IllegalAccessException: Class com.vaadin.data.util.MethodProperty can not access a member of class com.example.twoview.view.select.ComboBoxView$FakePerson with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at com.vaadin.data.util.MethodProperty.getValue(MethodProperty.java:608)


Simply, make it a public static class:

Good Class


public static class FakePerson {
private String name;
private Integer age;

FakePerson(String name2, Integer age2) {
this.name = name2;
this.age = age2;
}
public static FakePerson create(String name2, Integer age2) {
return new FakePerson(name2, age2);
}
public String getName() {
return name;
}
public Integer getAge() {
return age;
}
}


Bad Class


static class FakePerson {
private String name;
private Integer age;

FakePerson(String name2, Integer age2) {
this.name = name2;
this.age = age2;
}
public static FakePerson create(String name2, Integer age2) {
return new FakePerson(name2, age2);
}
public String getName() {
return name;
}
public Integer getAge() {
return age;
}
}

Related Posts by Categories

0 comments:

Post a Comment