A simple table problem...

Hello everyone.

I work with vaadin since 4 month and I have faced many problems. Because of the delays, I “bypassed” some good practices. But now I have some time, and I want to improve my skills with vaadin.

My current problem is the following :

I have a table, in this table I want to put some bean form a database :

Bean :

public class Year {

    private Long id;

    private Integer number;

//Constructor, getters and setters, other attributes ...

At starting, I retrieve all the beans from database and put them into a table. The problem is that beans look like that :


core.entity.Year@27787775

I found that writing a custom “toString” method in my bean “Year” results with good names in the table, but I know that this is not the way it should be done.

So, my first question is :

  1. Is it possible to put a bean in a table with just one column which is a kind of “alias” for the bean?

Secondly I faced some problem when I want to retrieve the bean by clicking it in the table. Actually I am doing this like that :

Item item = tableYear.getItem(tableYear.getValue()); Year year = (Year) item; But I have this exception :


java.lang.ClassCastException: com.vaadin.data.util.IndexedContainer$IndexedContainerItem cannot be cast to core.entity.Year

In fact, I just want to put a bean in a table and retrieve it by clicking on it. (I know how to do it the wrong way)

I sure this is possible but I am kind of lost right now.

Thanks for your help !!

Dassa-

You definately want to start looking into using BeanContainer as the table source container.

Take a look at 8.5.4:
link

This will get you pretty far. The bean container makes it easy to iterate thru the table and access the selected items as you wanted.

Regards,
Eric

Thank you Eric, I will read that right now.

Okay Eric, It works perfectly, thank you very much

Dassa-

Not a problem…it’s a good framework with so many good tools!

Regards,
Eric