2

I have some trouble working with dynamically-generated trees, i.e. trees whose leaves are read from the database.

In my app, I am showing a list of problems (in a rich datatable). When the user clicks on a problem, a tree containing names of photos associated to that problem is shown. Even though the photos associated to the selected problem are correctly read from the database, the tree's leaves contain only the default test values that I set in the beginning.

Relevant snippets:

The tree is contained in a form and it looks like this:

<rich:tree style="width:300px" 
    nodeSelectListener="#{treeBean.processSelection}"
    reRender="selectedNode" 
    ajaxSubmitSelection="true" 
    switchType="server" 
    value="#{treeBean.treeNode}">
</rich:tree>

And in the bean I have the method for getting the treeNode: public TreeNode getTreeNode()

I have debugged this and I don't understand how it works. Does something else happen to the value of treeNode between the return of getTreeNode() and the displaying in the rich:tree? I print out the value of treeNode right before the return of getTreeNode() and it is correct, but the displayed value is not the one printed out.

Can anyone explain why this happens and/or how this works internally? Thanks!

EDIT: After debugging in more detail, I think that the getTreeNode() method is only invoked once, during rendering of the page on which the tree will be shown. How can the rich:tree component be forced to call this method every time the tree is to be shown?

4
  • 1
    Do you hav a reRender="treeId" when a problem is clicked?
    – morja
    Feb 28, 2011 at 11:30
  • @morja: Thanks, in the meantime I have solved it by coming to the same conclusion -- I re-render the tree and it works!
    – ACEG
    Feb 28, 2011 at 11:33
  • @morja again: I would vote up your answer, but don't have enough rep points for that - sorry!
    – ACEG
    Feb 28, 2011 at 11:53
  • Don't worry, hasn't been a proper answer anyway... But I can give you some points, for the next time;-)
    – morja
    Feb 28, 2011 at 15:57

1 Answer 1

3

Solved by re-rendering the tree. There might be a more elegant solution, but this works for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.