little help on nodeSelectListener for different treeNodes
meghiddo Jul 25, 2009 9:59 AMI have a tree that has projects, devices, and channels. I have two beans for this tree, one called DeviceChannels that holds each device and list of its channels, with these variables:
private String deviceName;
private String deviceId;
private String channelId;
List channelsList = new ArrayList();
Then I have ProjectHolder class to hold the name of each projects, and a List of this DeviceChannels class. Here are the variables:
private String projectName;
private String projectId;
List deviceAndChannels = new ArrayList();
In this way I am able to bind only the ProjectHolder class to the rich:tree, but since it has the List of DeviceChannels Objects I am able to get access to both Objects and only having to bind ProjectHolder to the rich:tree.
I am working on nodeSelectListener methods, but I have trouble with clicking any node other than the top project name node. Clicking that node I can have my code do whatever I need, such as pulling the IDs from that project node and the device cnd channel nodes beneath it.
But if I try to click on the second or third ndoes, I get these types of errors:
nodeSelectListener="#{treeClickBean.projectSelection}": java.lang.ClassCastException: nodesContainer.DeviceChannels cannot be cast to nodesContainer.TreeHolder
Here is the tree as it is now and the projectSelection method that nodeSelectListener calls:
<rich:tree nodeSelectListener="#{treeClickBean.projectSelection}" ajaxSubmitSelection="true" switchType="client"
var="item" ajaxKeys="#{null}" reRender="projectForm">
<rich:treeNodesAdaptor nodes="#{testNodesBean.projects}" var="projects">
<rich:treeNode>
<h:outputLink value="/NI/explorer_click/project.jsf">
<h:outputText value="#{projects.projectName}" />
</h:outputLink>
</rich:treeNode>
<rich:recursiveTreeNodesAdaptor roots="#{projects.deviceAndChannels}" var="device">
<rich:treeNode>
<h:outputLink value="/NI/explorer_click/device.jsf">
<h:outputText value="#{device.deviceName}" />
</h:outputLink>
</rich:treeNode>
<rich:recursiveTreeNodesAdaptor roots="#{device.channelsList}" var="channels">
<rich:treeNode>
<h:outputText value="#{channels}" />
</rich:treeNode>
</rich:recursiveTreeNodesAdaptor>
</rich:recursiveTreeNodesAdaptor>
</rich:treeNodesAdaptor>
</rich:tree>
public void projectSelection(NodeSelectedEvent event){
HtmlTree tree = (HtmlTree) event.getComponent();
projectNode = (TreeHolder) tree.getRowData();
projectId=projectNode.getProjectId();
projectName=projectNode.getProjectName();
deviceChannelsObject=projectNode.getDeviceAndChannels().get(projectNode.getDeviceindex());
deviceId=deviceChannelsObject.getDeviceId();
deviceName=deviceChannelsObject.getDeviceName();
}As you can see from the java code I can get the data from the child nodes just by clicking on the parent node, but I am having problems adjusting my java code to having the child nodes clicked on.
Should I make a separate method from projectSelection() or should I handle it in that same class?
Do I need to put separate nodeSelectListener attributes in the tree? Right now I just have one because calling that gives me access to all the data I need.
It seems like this should be handled in the java code there, because when I try to add a different nodeSelectListener to the device treeNode tag, it still gives me the same error from above.
I just need a little guidance on how to handle this.