views:

635

answers:

1

Hello

I am testing a project, using Vaadin and Hibernate. I am trying to use the HbnContainer class to show data into table. The problem is that I do not want to show all the properties of the two classes in the table.

For example:

@Entity
@Table(name="users")
class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;

@ManyToOne(cascade=CascadeType.PERSIST)
private UserRole role;

//getters and setters
}

and a second class:

@Entity
@Table(name="user_roles")
class UserRole {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String name;

//getters and setters
}

Next, I retrieve my data using the HbnContainer, and connect it to the table:

HbnContainer container = new HbnContainer(User.class, app);
table.setContainerDataSource(container);

The Table will only display the columns from User, and for the "role" it will put the role id instead. How can I hide that column, and replace it with the UserRole.name ?

I managed to use a ColumnGenerator() to get the string value in the table, for the UserRole - but I couldn't remove the previous column, with the numerical value.

What am I missing? Or, what is the best way to "customize" your data, before displaying a table (if i want to show data in a table from more than one object type.. what do I do?)

If I can't find a simple solution soon, I think I will just build the tables "by hand"..

So, any advice on this matter?

EDIT:
I did not express myself to well before. What I need to know is how to use nested pojos, with HbnContainer, and control what properties (and "sub-properties") appear in the table. I tried to Extend and reimplement some parts of HbnContainer, but.. couldn't do it properly.

For the previous example, the table generated from the Users table looks like:

Name  |Role
George| 1
Alex  | 2 

I want something like:

Name  | Role
George| admin
Alex  | user

Thank you,
Alex

A: 

What you want to do is to define which properties should be visible in the table (thus excluding the role id). This can be achieved with the setVisibleColumns() method.

Kim L