Hi,
I have requiremnet to add new property into container at runtime.So is there anyway to achive same?I am using container.addContainerProperty() but it throwing an error.
Hi,
I have requiremnet to add new property into container at runtime.So is there anyway to achive same?I am using container.addContainerProperty() but it throwing an error.
Hi,
which container are you using and what is the exact error you’re getting? Some containers prohibit adding new properties for good reasons.
I am using BeanContainer and getting Access Denied Error.Following is My CustomTable and Bean.
class CustomTable extends Table
{
BeanContainer<Long, MyBean> container;
public CustomTable()
{
init();
}
public void init()
{
container=new BeanContainer<>(MyBean.class);
container.setBeanIdProperty("id");
for(int i=1;i<=5;i++)
{
container.addBean(new MyBean(i));
for(int prop=1;prop<=24;prop++)
{
container.getItem(i).addItemProperty(prop,new ObjectProperty<>(new TextField(), TextField.class));
}
}
}
}
and MyBean.java
class MyBean
{
long id;
public MyBean(long id)
{
this.id=id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
You can’t use BeanContainers like that - the properties for those are taken from the beans directly. Since you’re using this for Table, could you just add your TextFields as generated columns to the Table?
It is also technically possible to add properties to a BeanContainer, but I would not recommend that approach unless you are deeply familiar with how BeanContainer, PropertySetItem, VaadinPropertyDescriptor etc. work and can use some semi-private APIs. This would involve defining custom implementations of VaadinPropertyDescriptor (if I remember the name correctly) and adding them to the container in a subclass using protected methods.
The approach of using a generated column is probably much simpler and safer, though, or a wrapper bean that adds accessors could be considered in some cases.
Thank you for giving reply of my question.
One thing i want ask you to Teppo/Henri suppose i am achive the same with generated columns but the problem is how to get values of generated columns?
I know that genertead columns are virtual columns and attached to a table.