Changes to the tree node are not reflected during ajax
andrew.rw.robinson Mar 20, 2007 7:24 PMI am trying to research the feasibility of using the tree for our needs (See http://tinyurl.com/25v9wl for more information). I created a custom tree node that changes it's children based on node selection. The tree is not reflecting any changes to the tree node hierarchy in my backing bean
XHTML:
<a4j:form id="testForm"> <rf:tree id="testTree" var="_data" switchType="ajax" ajaxSubmitSelection="true" preserveModel="none" value="#{ajaxTreeTest.rootNode}" nodeSelectListener="#{ajaxTreeTest.onTreeNodeSelection}" nodeFace="#{_data eq 'PagedTreeNode.movePrevious' ? 'movePrevNode' : (_data eq 'PagedTreeNode.moveNext' ? 'moveNextNode' : 'node' )}"> <rf:treeNode type="movePrevNode"> ^ Previous </rf:treeNode> <rf:treeNode type="node"> #{_data} Num selections: #{ajaxTreeTest.numSelections} </rf:treeNode> <rf:treeNode type="moveNextNode"> V Next </rf:treeNode> </rf:tree> </a4j:form>
Inside the "ajaxTreeTest.onTreeNodeSelection" I modify the node:
public void onTreeNodeSelection(NodeSelectedEvent evt) { log.info("Selected event: " + evt); HtmlTree tree = (HtmlTree)evt.getComponent(); TreeRowKey key = (TreeRowKey)tree.getRowKey(); log.info("Key: " + key); TreeNode node = rootNode; if (PagedTreeNode.MOVE_NEXT_ID.equals(tree.getRowData()) || PagedTreeNode.MOVE_PREV_ID.equals(tree.getRowData())) { for (Iterator iter = key.iterator(); iter.hasNext();) { Object id = iter.next(); log.info("ID: " + id); node = node.getChild(id); log.info("Node: " + node); } if (PagedTreeNode.MOVE_NEXT_ID.equals(node.getData())) { PagedTreeNode parentNode = (PagedTreeNode)node.getParent(); parentNode.setStartAt(parentNode.getStartAt() + parentNode.getPageSize()); log.info("New start at: " + parentNode.getStartAt()); } else if (PagedTreeNode.MOVE_PREV_ID.equals(node.getData())) { PagedTreeNode parentNode = (PagedTreeNode)node.getParent(); parentNode.setStartAt(parentNode.getStartAt() - parentNode.getPageSize()); log.info("New start at: " + parentNode.getStartAt()); } } }
Log output:
17:15:25,535 INFO [TestAjaxTree] Selected event: org.richfaces.component.events.AjaxSelectedEvent[source=org.richfaces.component.html.HtmlTree@2a821] 17:15:25,536 INFO [TestAjaxTree] Key: PagedTreeNode.moveNext 17:15:25,536 INFO [TestAjaxTree] ID: PagedTreeNode.moveNext 17:15:25,536 INFO [TestAjaxTree] Node: org.richfaces.component.TreeNodeImpl@6c4a07 17:15:25,537 INFO [TestAjaxTree] New start at: 20
When I refresh the page, the tree is correct. I was hoping that the tree renderer would automatically detect that some nodes were removed and some were added (by their IDs), but that was not the case. Is there any way in the AJAX rendering model to flag the nodes as dirty so that they get updated?