HierarchicalContainer and a Tree = confusion

I’m sure I must be doing something wrong, but I can’t seem to figure out what is happening here. I have a need to display differing views depending upon if a user clicks on a leaf item in the tree, or if they click on a parent item. The Tree is also backed by a HierarchicalContainer object. I can render the tree correctly, and I can indeed drill down as expected within the tree, but I’m having a hard time determining the content of the item selected.

I’ve used a ValueChangeListener to detect which item in the tree is clicked on, and I CAN see valid property IDs in the event, but the Item itself is always null. For example, this code (purely for information only) is included in the valueChange event handler (I’d never use S.O.P in real code; I’m just trying to find out why the Item is always null here):


Collection ids = mergeTree.getItem(event.getProperty().getValue()).getItemPropertyIds();
for (Object id : ids) {
        System.out.println("ID: " + id);
	Object name = mergeTree.getItem(event.getProperty().getValue()).getItemProperty(id);
	System.out.println("Name: " + name );
}

The output is something like this in the console:


INFO: ID: name
INFO: Name: null
INFO: ID: container
INFO: Name: null

Any tips or hints at what I’m most likely doing wrong?

Is this posted, perhaps, in the wrong section? It seems that there is at least someone replying to other posts but this one sits ignored… I took a shower this morning and my pits don’t stink. :slight_smile:

If you want to get back the object you set using addItem(object), or setting the container where your objects are, that’s what you get from event.getProperty().getValue() already – it’s the itemId of the created Item, and as such the most likely candidate for useful comparisons. The Item that corresponds to that itemId won’t hold much information unless you explicitly give it some. If you truly had a null Item you would get NullPointerException when you try to get those itemPropertyIds from it.

I think I’ve found the issue and have resolved it. The Tree is backed by a JPAContainer of objects, and I was indeed looking at the addItem object and not at the container underneath. Fixing the reference passed into the event solved it.