我是使用rich:tree组件的新手。当我有3个节点时,我的selectionChangeListener
方法被正确调用。但是,当选择最里面的节点时,空参数(selectionChangeEvent.getNewSelection()
)将被发送到selectionChangeListener
方法。
我找不到问题。
<h:panelGrid>
<rich:tree nodeType="#{node.type}" value="#{kampusBean.mevcutkampus.rootnodes}" var="node"
selectionChangeListener="#{kampusBean.mevcutkampus.selectionChanged}"
toggleType="client" selectionType="ajax" render="paftapanel">
<rich:treeNode type="Node1">
#{node.name}
</rich:treeNode>
<rich:treeNode type="Node2">
#{node.name}
</rich:treeNode>
<rich:treeNode type="Node3">
#{node.name}
</rich:treeNode>
<rich:treeNode type="Node4">
#{node.name}
</rich:treeNode>
</rich:tree>
<a4j:commandButton image="/resources/add.png" action="#{kampusBean.mevcutkampus.addNode1()}"
render="paftapanel"/>
</h:panelGrid>
选择侦听器方法:
public void selectionChanged(TreeSelectionChangeEvent selectionChangeEvent) {
List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection());
if (selection == null || selection.isEmpty()) {
return; //when node4 is selected, selection is empty and always returns.
}
Object currentSelectionKey = selection.get(0);
AbstractTree tree = (AbstractTree) selectionChangeEvent.getSource();
Object storedKey = tree.getRowKey();
tree.setRowKey(currentSelectionKey);
mevcutSecim = (TreeNodeLevel) tree.getRowData();
tree.setRowKey(storedKey);
}