Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
GeneratedPropertyContainer and CommitHandler, getting the Bean data?
I previously had a BeanItemContainer for my Grid, but I needed to add a column in my grid for a button, so I used a GeneratedPropertyContainer.
But I'm getting the error:
Caused by: java.lang.ClassCastException: com.vaadin.data.util.GeneratedPropertyContainer$GeneratedPropertyItem cannot be cast to project.test.Bean
how do I get the Bean from GeneratedPropertyContainer?
For BeanItem Container, I could do this:
public class CustomCommit implements CommitHandler {
public CustomCommit() {
}
@Override
public void preCommit(CommitEvent commitEvent) throws CommitException {
BeanItem item = (BeanItem) commitEvent.getFieldBinder().getItemDataSource();
Bean bean = (Bean) item.getBean();
}
But for GPC I can't figure out how to get the bean?
The item in the wrapped case is a GeneratedPropertyItem (as the exception indicates). You can use GeneratedPropertyItem.getWrappedItem() to get the original BeanItem, and then get the bean from it. This does require an extra cast, though.
Thank you, that worked!
public class CustomCommit implements CommitHandler {
Bean beanPrevious = null;
@Override
public void preCommit(CommitEvent commitEvent) throws CommitException {
GeneratedPropertyItem gpItem = (GeneratedPropertyItem) commitEvent.getFieldBinder().getItemDataSource();
BeanItem item = (BeanItem) gpItem.getWrappedItem();
Bean bean = (Bean) item.getBean();
...
}