Reputation: 2983
I'm developing a vaadin application and now have the following trouble. I'm trying to bind a nested property along BeanFieldGroup.
MyEntity Class
@Entity
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private MyEntityPK id;
//Others Property
public MyEntityPK getId() {
return this.id;
}
public void setId(MyEntityPK id) {
this.id = id;
}
}
MyEntityPK Class
@Embeddable
public class MyEntityPK implements Serializable {
@Column(name="CD_VARIABILE")
private String cdVariabile;
public String getCdVariabile() {
return this.cdVariabile;
}
public void setCdVariabile(String cdVariabile) {
this.cdVariabile = cdVariabile;
}
}
MyVaadinPanel
private BeanFieldGroup<MyEntity> binder;
binder = new BeanFieldGroup<MyEntity>(MyEntity.class);
binder.setItemDataSource(new BeanItem<MyEntity>(new MyEntity()));
variabileBinder.bind(new TextField(), "id.cdVariabile");
When, I try to bind the property "id.cdVariabile" to TextFiel, I get the following error:
Caused by: com.vaadin.data.util.MethodProperty$MethodException
at com.vaadin.data.util.NestedMethodProperty.getValue(NestedMethodProperty.java:205)
at com.vaadin.data.util.TransactionalPropertyWrapper.getValue(TransactionalPropertyWrapper.java:73)
at com.vaadin.ui.AbstractField.getDataSourceValue(AbstractField.java:299)
at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:629)
... 48 more
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.data.util.NestedMethodProperty.getValue(NestedMethodProperty.java:201)
... 51 more
Where am I wrong ?
Upvotes: 1
Views: 1990
Reputation: 15518
Looks like when you create your entity in binder.setItemDataSource(new BeanItem<MyEntity>(new MyEntity()));
its id is null, hence trying to rerieve id.cdVariabile
would result in NPE.
Try adding a PK:
BeanFieldGroup<MyEntity> binder;
binder = new BeanFieldGroup<MyEntity>(MyEntity.class);
MyEntity myEntity = new MyEntity();
myEntity.setId(new MyEntityPK());
binder.setItemDataSource(new BeanItem<MyEntity>(myEntity));
binder.bind(new TextField(), "id.cdVariabile");
Upvotes: 2