get bean for table

I write the following

public BeanItemContainer<MyBean> getLista() {
		List<MyBean> lista = null;
		try {
			lista = this.getControl().getServiceBean().getListMyBean();
		} catch (ExcepcionDao e) {
		BeanItemContainer<MyBean> cr = new BeanItemContainer<MyBean>(lista);
		return cr;

getListMyBean() is a list obtained from the database, MyBean is

public class MyBean implements Serializable {

	private String name;
	private int id;
	.............................get and set...................

and try to get the bean by clicking on the table,I write the following

	public void valueChange(ValueChangeEvent event) {
		Property property = event.getProperty();
		if (property == myTable) {
			Item item = myTable.getItem(myTable.getValue());
			MyBean myBean=(MyBean)item;


and get the following error cannot be cast to MyBean
how to get the bean??

thanks in advance


Instead of:

Item item = myTable.getItem(myTable.getValue());
MyBean myBean=(MyBean)item;


BeanItem<MyBean> item = (BeanItem)myTable.getItem(myTable.getValue());
MyBean myBean=item.getBean();


Ok gracias from Chile

Or, even better, try MyBean myBean = (MyBean)myTable.getValue();

getValue() gives the item id and BeanItemContainer uses the bean itself as a item id for the rows.

work fine

MyBean myBean = (MyBean)myTable.getValue();

work fine

BeanItemContainer container = (BeanItemContainer) myTable
myBean = container.getItem(myTable.getValue()).getBean();

Gracias :lol: