public class LocationBasedRole extends AbstractEntity{
@ManyToMany(fetch=FetchType.LAZY)
private Set<Role> roles=new HashSet<Role>();
@ManyToMany(fetch=FetchType.LAZY)
private Set<Location> locations=new HashSet<Location>();
}
public class Role extends AbstractEntity{
private String name;
}
public class Location extends AbstractEntity{
private String location;
}
我有一个名为 locationBasedRole 的实体,它有 2 个名为角色和位置的属性。角色和位置都与 locationBasedRole 具有@ManyToMany 关系。
现在我想在 Vaadin 表中拥有每个属性。
应该是这样的
public class UserForm extends OgsAbstractForm<User>{
MTable<LocationBasedRole> locationBasedRoleTable = new MTable<LocationBasedRole>().withHeight("100%").withWidth("100%");
@Override
protected Component createContent() {
Set<LocationBasedRole> lbRoles=new HashSet<LocationBasedRole>();
roles.addAll(locationBasedRoleFasade.findAll());
BeanItemContainer<LocationBasedRole> bean=new BeanItemContainer<LocationBasedRole>(LocationBasedRole.class);
//It returns an error on the next both lines and I know the reason, but don't know how to solve it.
// If it was no ManyToMany relation and the properties weren't a collection, it would work
bean.addNestedContainerProperty("roles.name");
bean.addNestedContainerProperty("locations.location");
bean.removeContainerProperty("persistent");
bean.removeContainerProperty("id");
bean.addAll(lbRoles);
locationBasedRoleTable.setContainerDataSource(bean);
return new VerticalLayout(locationBasedRoleTable);
}
}
当我从 NestedContainerProperties 中删除属性时,它至少向我显示了表格中的某些内容。
bean.addNestedContainerProperty("roles");
bean.addNestedContainerProperty("locations");
我可以使用任何帮助!
提前致谢!