'JSF Access to child data elements from parent for decision making

please help me with this situation: I will try to explain what needs to be done. I apologize if my wording is not clear, but I am just starting with the JSF primefaces, and may not phrase things correctly.

The tree bellow, works fine. As you can see, the treeNode 'ACTION' is a child of 'STEP'. And there is a spyglass to be displayed (images/view.gif) that is clickable to download a file. This part works just fine.

<p:tree id="treatmentStepTree" value="#{pageBean.steps}" 
   var="node" styleClass="custom-tree-no-border"
   selectionMode="single"
   selection="#{pageBean.selectedNode}">
 <p:ajax event="select" listener="#{pageBean.setTreatmentActionData}"
        update="form1:actionDesc form1:actionSkip form1:CompletionDateId:completionDateField 
   form1:actionComment"/>
 <p:ajax event="contextMenu" listener="#{pageBean.setActionData}"
        update="form1:actionDesc form1:actionSkip form1:CompletionDateId:completionDateField 
  form1:actionComment"/>

  <p:treeNode type="#{nodeType.STEP.typeName}">
   <span style="cursor: pointer;" onclick="this.parentNode.parentNode.firstChild.click();">
       <h:outputText value="#{node}"/>
   </span>
  </p:treeNode>

  <p:treeNode type="#{nodeType.ACTION.typeName}">
    <p:commandLink id="viewFile" ajax="false" value="# 
    {pageBean.ActionUIData.letterType}"
            title="#{pageBean.ActionUIData.letterStatus}">                                                
         <p:fileDownload value="#{pageBean.ActionUIData.viewLetterFile}" />
         <p:graphicImage value="/images/view.gif" title="View File"/>
   </p:commandLink>                                            
   <h:outputText value="#{node.summaryString}"/>
 </p:treeNode>
</p:tree>

Question is this: spyglass to be displayed ONLY IF the letter is available. Availability of the letter is available on the 'ACTION' level, and a 'STEP' can have multiple 'ACTION's, with or without letter. So, I want to use a "rendered" attribute binded to some condition .. but I do not know know how to implement the boolean condition that would dictate whether the file is available on the 'ACTION' or not.

In the following part, what would I put into the "rendered" attribute ? In the backing bean pageBean, I mantain a Map with actions ids as keys and boolean true/false representing if a file exists / available. I do have that. But since there are multiple actions, how to access a concrete flag? what/how do I pass from JSF page ??

<p:commandLink id="viewFile" ajax="false" value="# 
    {pageBean.ActionUIData.letterType}"
            title="#{pageBean.ActionUIData.letterStatus}" 
  rendered="????">                                                
         <p:fileDownload value="#{pageBean.ActionUIData.viewLetterFile}" 
 />
         <p:graphicImage value="/images/view.gif" title="View File"/>
   </p:commandLink>

This is a question on JSF prime faces !! I do not know what to do from the point of view of the framework.

I do have the way to tell if the file is on the action or not.
Data structure is: step object has a list of actions. every action object has a few fields related to file - file path, file name, status, etc... not important. what is important, that upon construction of the nodes, I do not know how to tie a single boolean condition to the "knowledge" about the existence of the file.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source