basically what i'm trying is to update an image with regard to the node selected in a tree.it would work perfectly if I used the same backing bean for both components but I need to use different beans for each component. I've tried to intanciate the image's bean from the tree's bean but it doesn't work. I suppose the image component is updated before the images class is called so it doesn't have the data on time. Here you have the code to keep it clearer:
Code: Select all
<p:tree id="tree" value="#{TreeBean.root}" var="node"
selectionMode="single"
ajax="false"
selection="#{TreeBean.selectedNode}"
nodeSelectListener="#{TreeBean.onNodeSelect}"
update="image">
<p:treeNode type="location" >
<h:outputText value="#{node}" />
</p:treeNode>
<p:treeNode type="device">
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
<h:graphicImage id="image" value="images/#{ImagesBean.currentImage.url}">
Code: Select all
public void onNodeSelect(NodeSelectEvent event) {
if(event.getTreeNode().getType().equals("location")){
Images aux = new Images();
aux.getImage(selectedNode);
}
Code: Select all
public void getImage(String selectedNode){
Iterator iLocation = locationCol.iterator();
while (iLocation.hasNext()){
Location l = (Location)iLocation.next();
if(selectedNode.equals(l.getId())){
currentImage = l.getImage();
}
}