Kiesa
Kiesa

Reputation: 407

How can i access my Objects in a vaadin tree?

I`ve added my own objects into a vaadin tree like this:

Item item = container.addItem(planet); //where planet is from class Planet

If I get it right, only the string taken from planet.toString() will be added to my tree.

Now I need to access several methods/attributes of my object (e.g. getMoons() or getPlanetID()). How can I access my object by selecting this planet in my tree (via getValue() in my valueChanged-event) ?

Upvotes: 1

Views: 1968

Answers (1)

miq
miq

Reputation: 2766

Try this:

Planet myPlanet = (Planet) myTree.getValue();
myPlanet.getMoons();

Since the itemId is an instance of Planet, you can safely cast the getValue() result into such.

If you need the container in some other context, check BeanItemContainer out.

Upvotes: 2

Related Questions