Eddy Freeman
Eddy Freeman

Reputation: 3309

Creating JSF Tree Structure

I know JSF doesn't have a Tree component but am trying to create Tree hierarchy from system files. The root folder has files and subfolders, that in turn also has files and subfolders. This is what I have in my view now but it is not working when I click on the commandLink/plus-icon:

<!-- main.xhtml -->

<ui:include src="node.xhtml">
    <ui:param name="directory" value="#{myBean.myListing}"></ui:param>
</ui:include>
        
        
 "myListing" consists of ArrayList of folders and files



<!-- node.xhtml -->

<ui:composition>
    <ui:repeat value="#{folder}" var="myItem">
        
            <h:commandLink action="#{myBean.showMyChildren}">
                <h:graphicImage value="images/plus.png" rendered="#{!item.file and (myItem.children.size() > 0)}"/>
            </h:commandLink>
            <h:graphicImage value="images/directoryImage.png" rendered="#{!myItem.file}"/>
            <h:graphicImage value="images/mybutton.png" rendered="#{myItem.file}"/>
            <h:outputText value="#{myItem.fileName}" > <br />
            
            <h:panelGroup rendered="#{myBean.revealChildren}" >
                <c:if test="#{myItem.children.size()>0}">
                    <ui:include src="node.xhtml" >
                    <ui:param name="dir" value="#{myItem.children}"></ui:param>
                </ui:include>  
            </c:if>
        </h:panelGroup> 
    </ui:repeat>    
</ui:composition>

myBean

At the moment only the files and folders at the top level (in the root folder) are shown when the page is displayed. When click on the "plus" icon infront of the folders, its children are not displayed. It means that "rendered="#{myBean.revealChildren}" in "node.xhtml" is not working.

In my "showMyChildren()" method I set "revealChildren" variable to "true" when the commandLink/plus-icon is clicked, yet the children never get revealed.

I know there are libraries like Primefaces and Icefaces that have Tree components but I want to build a customised Tree in JSF myself. Would this be a viable direction?

I am also willing to create my own Tree component like the ones in Primefaces or Icefaces.

Upvotes: 0

Views: 1012

Answers (0)

Related Questions