please help BeanItemContainer or IndexedContainer


I have a claseA
I have a claseB

And the classA To contains a class B

From the database I obtain a list of classA To and then I do the following thing

BeanItemContainer <ClaseA> cr = new BeanItemContainer <ClaseA> (lists);


And the table is seen this way

NombreA NombreB
Jorge com.prueba.ClassB@452151

as the property is not claseB name, do the following

List<ClassA> lista = null;
lista = this.getControlador().getServicio().getListaClassA;
//BeanItemContainer<Ciudad> cr = new BeanItemContainer<Ciudad>(lista);
IndexedContainer cr = new IndexedContainer();
cr.addContainerProperty("nombre A", String.class, "");
cr.addContainerProperty("nombre B", String.class, "");
for (Ciudad ci : lista) {
		Item item = cr.addItem(ci);
			item.getItemProperty("nombre  A").setValue(ci.getNombre());
			item.getItemProperty("nombre  B").setValue(ci.getClassB().getNombre());

Then he was so

NombreA NombreB
Jorge Maria

so is right, but it is the best way

this is how it works when there are class-related??

I am not certain if I understood exactly what you want to achieve, so is the situation like this:

You retrieve objects from a database so that some of them have references to objects of the other type. You want to display those references as something human readable, and you do not want or cannot add a suitable toString() method in claseB.

I am assuming that the claseB instance in claseA and its name are not lazily loaded by JPA/Hibernate, or that you are using a database library that handles lazy loading outside of the original transaction gracefully (I believe EclipseLink does, Hibernate does not).

One way to do this with a generated column that has the same name as the original property, and that returns a Label with the name. When you adding a generated column with the same property name as a normal visible column in the table, it “overrides” the original one in your table. This way, you would still keep all the other functionality of BeanItemContainer, even though your example would not really be shorter.

Such formatting etc. should get easier in future versions of Vaadin.

Note also that if you use BeanItemContainer, the bean identifiers, which in BeanItemContainer are the beans (entities) themselves, should have equals() and hashCode() methods based on their (database) identifiers. In Vaadin 6.5, there will be an alternative to BeanItemContainer that allows the item identifiers to be something else than the beans themselves, e.g. directly their database identifiers extracted from the beans.

I have the following class :

1.- Class A

package com.dominio;

public class ClassA {
   private String name;
   private ClassB classB;

public String getName() {
	return name;

public void setName(String name) { = name;

public ClassB getClassB() {
	return classB;

public void setClassB(ClassB classB) {
	classB = classB;

2.- Class B

package com.dominio;

public ClassB(){}

public class ClassB {
  private String name;

public String getName() {
	return name;
 public void setName(String name) { = name;

I get the data from the database and write the following:

public BeanItemContainer<ClassA> getListClassA() {
		List<ClassA> lista = this.getControl().getServiceClassA().getListClassA();
		BeanItemContainer<ClassA> containerClassA = new BeanItemContainer<ClassA>(lista);
		return containerClassA;

and then in the table :


and I get the below, which is incorrect:

Name Class A Name Class B
Henri com.ClassB@1687dcd

must show the following, which is correct:

Name Class A Name Class B
Henri Eric

I need to write in class A or B, or I have to do something more to beanItemContainer to display data correctly in the table?

thank you very much:grin::grin::grin:

HI Eric & Henri

Will you plz share the implementation for the above criteria. I am also looking for similer implementation