nodeSelectListener not fired, root node does not display
bolsover Jun 1, 2009 3:59 AMI'm having a problem with a tree where a nodeSelectListener registered on the treeNode is not being fired; I'm reasonably sure I must be overlooking something obvious...
Additionally, I have had to add an additional (dummy parent) treeNode since the root node does not display.
The tree displays just fine and nodes expand colapse as required.
Page code:
<h:form>
<h:panelGrid columns="2" width="100%">
<rich:tree style="width:600px" switchType="client" value="#{BillExplosionBean.rootNode}" var="item" >
<rich:treeNode reRender="selectedNode" ajaxSubmitSelection="true" nodeSelectListener="#{BillExplosionBean.processSelection}" >
<h:outputText value="#{item.seq}" />
<h:outputText value=": " />
<h:outputText value="#{item.part}" />
<h:outputText value=": " />
<h:outputText value="#{item.usage}" />
</rich:treeNode>
</rich:tree>
<h:outputText escape="false" value="Selected Node: #{BillExplosionBean.nodeTitle}" id="selectedNode" />
</h:panelGrid>
</h:form>
Bean Code:
/** Creates a new instance of BillExplosionBean */
public BillExplosionBean() {
}
// set-up root node and call recursive method
public void retrieveBill(String parent){
rootNode = new TreeNodeImpl();
Bill bill = new Bill();
bill.setPart(parent);
// dummy parentNode since rootNode does not display
TreeNode parentNode = new TreeNodeImpl();
parentNode.setData(bill);
rootNode.addChild(bill, parentNode);
List<Bill> bills = dao.retrieveBillByParent(parent);
walkTree(parentNode, bills);
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
HttpSession httpSes = (HttpSession) ec.getSession(false);
httpSes.setAttribute(AppConstants.BILL_EXPLOSION_BEAN, this);
}
// recursive method to construct the tree
private void walkTree(TreeNode parent, List<Bill> bills){
for (Bill bill : bills){
// do some processing to build the tree
TreeNodeImpl nodeImpl = new TreeNodeImpl();
nodeImpl.setData(bill);
parent.addChild(bill, nodeImpl);
// get the subordinate parts
List<Bill> childBills = dao.retrieveBillByParent(bill.getPart());
walkTree(nodeImpl, childBills);
}
}
// node selection event
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (String) tree.getRowData();
selectedNodeChildren.clear();
TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()){
selectedNodeChildren.add((String)currentNode.getData());
}else
{
Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();
while (it!=null &&it.hasNext()) {
Map.Entry<Object, TreeNode> entry = it.next();
selectedNodeChildren.add(entry.getValue().getData().toString());
}
}
}
Any help correcting these problems would be appreciated.
David