Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to develop a tree menu using Java Server Faces?

Posted on 2009-04-11
4
Medium Priority
?
1,168 Views
Last Modified: 2013-11-24
Could anyone guide me on how to develop a dynamic tree menu using Java Server Faces? The requirement is such that: There will be a root menu "Projects". When it is clicked, it should expand with a list of projects and each project should have a sub-menu with the modules related to that project. The nodes "Projects" and "Modules" are static, whereas the content should be dynamically loaded. Diagramatically, it should be as below:

Before Clicking "Projects":
+ Projects
After Clicking "Projects"
- Projects
     + ERP
     + Oracle
     + Java
After Clicking on "ERP"
- Projects
      - ERP
           + Modules
      + Oracle
      + Java

Can it be achieved without using "JavaScript"?
0
Comment
Question by:visu_nekk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 24122071
I created a page for our project.We have used Apache Myfaces rather than reference implementation.

Attached is the image of my tree
private TreeModel hierarchyTree;
    private HierarchyNode hierarchyRootNode;
    public TreeModel getHierarchyTree()
    {
        if(hierarchyRootNode == null)
  hierarchyRootNode = new HierarchyNode(0, "NONE", "MyRoot", false);
    
        hierarchyTree = new TreeModelBase(hierarchyRootNode); 
        addChildren(hierarchyRootNode);
 
        return hierarchyTree;
    }
 
 
public void setHierarchyTree(org.apache.myfaces.custom.tree2.TreeModel t) { this.hierarchyTree = t; }
 
 
private void addChildren(HierarchyNode currentNode)
    {
       
        for(Iterator i = currentNode.getChildren().iterator(); i.hasNext(); )
        {
            addChildren((HierarchyNode)i.next());//This is a recursive funtion
        }
 
Getting Child Nodes from database
@Override
    public List getChildren()
    {
        loadChildren();
        return children;
    }
 
Loading the Children List
 
 public void loadChildren()
    {
        if(childrenLoaded) return;
 
        Connection connection = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try
        {
                String sql = "select * from Yourtable where PARENT_ID = ? ";
            connection = DB.getConnection();
            ps = connection.prepareStatement(sql);
            int i=1;
            ps.setInt(i++, id);
            ps.setString(i++, type);
            rs = ps.executeQuery();
            while(rs.next())
            {
                int cId = rs.getInt("CHILD_ID");
                String cType = rs.getString("CHILD_TYPE");
                String cName = rs.getString("CHILD_Name");
    HierarchyNode cNode = new HierarchyNode(cId, cType, cName, false);
                addChild(cNode);
            }
            childrenLoaded = true;
        }
        catch(Exception e) { log.error(e,e); }
        finally { DB.close(rs, ps, connection); }
    }
    }
 
 
FINALLY IN YOUR XHTML THIS IS HOW YOU HAVE
<div>Hierarchy:
                                    <t:tree2 value="#{bean.hierarchyTree}" id="hierarchyTree" var="node" showRootNode="false" preserveToggle="false" >//where bean is your bean.Make sure you spell the getter method exactly as in bean(case) 
                                        <f:facet name="hierarchy">
                                            <h:panelGroup>
                                            <t:selectBooleanCheckbox value="#{node.checked}" title="#{node.description}"/>
                                            <h:outputText value="#{node.description}"/>
                                            </h:panelGroup>
                                        </f:facet>
                                    </t:tree2>
                                </div>

Open in new window

tree.JPG
0
 

Author Comment

by:visu_nekk
ID: 24174271
Is it possible to add a right click menu on the nodes using MyFaces? For example,
When I right click on West, a menu should be displayed with options "Add nodes to West" and "Delete West".Similarly  when I right click on East, a menu should be displayed with options "Add nodes to East" and "Delete East".
0
 
LVL 15

Expert Comment

by:spprivate
ID: 24298415
I havent gone so far in JSF.Sorry
0
 
LVL 1

Accepted Solution

by:
pips06 earned 1500 total points
ID: 24533536
I suggest that you try Visual Web JSF framework cause it has some basic components and some advance components just like the tree component you can just drag and drop it to the stage and you can input your data there.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question