Vaadin table rows

vaadin

I'm using vaadin for UI,I have a entity class which has @OneToMany relationship, so Entity class has a list. so I want to display those values in a vaadin table,Could anyone explain me how to do that? Thank you, here is my class details

@OneToMany
private List<Driver> driverList = new ArrayList<Driver>()

This field in TempLocation class.

so when I query from the data I get one city and list of drivers. In vaadin table I could display query result in a single row(assume I have only one record in a database with more than one Driver)

Lets say my table has two columns "Location" and "Driver", so I want to display the results in multiple rows,I want to go through the List and take one drive at time display along with the City

Currently how it display in the table.

|Driver_______________| Location | (Table head)
[Driver1,Driver2,Driver3] | Kolonnanwa (row)

I want display this

|Driver______________| Location | (Table head)
Driver1
______________|Kolonnawa (row 1)
Driver2______________| Kolonnawa (row 2)
Driver3______________| Kolonnanwa (row 3)

"_" used to display spaces ,

Hope you got what I want to express and can anyone tell me how to do this?
Thankxx in Advance

Thank you,
Cheers

Best Answer

If you only want a different way of filling the table , I recommend just iterating over the List of your drivers and create one row for everyone (assuming every driver knows his city)

Check this example:

/* Create the table with a caption. */
Table table = new Table("This is my Table");

/* Define the names and data types of columns.
 * The "default value" parameter is meaningless here. */
table.addContainerProperty("Driver", String.class,  null);
table.addContainerProperty("City",  String.class,  null);

/* Add a few items in the table. */
int i = 1; 
for(Driver driver : driverslist){
table.addItem(new Object[] {
driver.getName(),driver.getCity(), new Integer(i));
i++
}

The Integer in the addItem()-method is for the rownumber.

Please check the articles given in the vaadin book about the use of the table component.

Related Topic