1 Reply Latest reply on Aug 19, 2007 6:58 PM by leon qian

    how to update the data of tree with richfaces?

    leon qian Newbie

      i have some code for showing and editing the tree. i am a stranger for richfaces and feel puzzle . my code like this:


      package com.WCRM.departmenttree;
      import java.io.ByteArrayOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.List;
      import java.util.Map;
      import java.util.StringTokenizer;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.jboss.seam.Component;
      import org.jboss.seam.Seam;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.log.Log;
      import org.richfaces.component.TreeNode;
      import com.WCRM.department.Department;
      import com.WCRM.department.DepartmentFinder;
      import com.WCRM.departmenttree.Department1;
      public class Library implements TreeNode {
       private static final long serialVersionUID = -3530085227471752526L;
       private Map brachs = null;
       private static Log log;
       private Map getBrachs() {
       //System.out.println("private Map getBrachs() ");
       if (this.brachs == null) {
       return this.brachs;
       public void addBrach(Branch brach) {
       ///System.out.println("public void addBrach(Brach brach) ");
       addChild(Long.toString(brach.getId()), brach);
       public void addChild(Object identifier, TreeNode child) {
       //System.out.println("public void addChild(Object identifier, TreeNode child)");
       getBrachs().put(identifier, child);
       public TreeNode getChild(Object id) {
       //System.out.println("public TreeNode getChild(Object id) ");
       return (TreeNode) getBrachs().get(id);
       public Iterator getChildren() {
       //System.out.println("public Iterator getChildren()");
       return getBrachs().entrySet().iterator();
       public Object getData() {
       //System.out.println("public Object getData()");
       return this;
       public TreeNode getParent() {
       //System.out.println("public TreeNode getParent()");
       return null;
       public boolean isLeaf() {
       System.out.println("public boolean isLeaf() ");
       // return false;
       return getBrachs().isEmpty();
       public void removeChild(Object id) {
       //System.out.println("public void removeChild(Object id)");
       public void setData(Object data) {
       public void setParent(TreeNode parent) {
       public String getType() {
       // System.out.println("public String getType()");
       return "library";
       private long nextId = 0;
       private long getNextId() {
       // System.out.println("private long getNextId()");
       return nextId++;
       private Map departmentCache = new HashMap();
       private Map departmentCache1 = new HashMap();
       private Map departmentCache2 = new HashMap();
       //private Map departmentCache3 = new HashMap();
       private Map brachCache = new HashMap();
       private Branch getBrachByName(String name, Library library) {
       Branch brach = (Branch) brachCache.get(name);
       if (brach == null) {
       brach = new Branch(getNextId());
       brachCache.put(name, brach);
       return brach;
       private Department1 getDepartment1ByTitle(String title, Branch brach) {
       Department1 department1 = (Department1) departmentCache1.get(title);
       if (department1 == null) {
       department1 = new Department1(getNextId());
       departmentCache1.put(title, department1);
       return department1;
       private Department2 getDepartment2ByTitle(String title,
       Department1 department1) {
       Department2 department2 = (Department2) departmentCache2.get(title);
       if (department2 == null) {
       department2 = new Department2(getNextId());
       departmentCache2.put(title, department2);
       // brach.addDepartment(department);
       return department2;
       private void initData2() {
       brachs = new HashMap();
       List<Department> items = null;
       DepartmentFinder em =
       if (items.size() > 0) {
       for (Department item : items) {
       System.out.println("line is started:");
       System.out.println("the selected dept:"+item.getDeptId());
       String employerTitle = item.getEmployer();
       String brachName = item.getBranch();
       String department1name = item.getDepartment1();
       String department2name = item.getDepartment2();
       Branch brach = getBrachByName(brachName, this);
       Department1 department1 = getDepartment1ByTitle(
       department1name, brach);
       Department2 department2 = getDepartment2ByTitle(
       department2name, department1);
       Employer employer = new Employer(getNextId());
       System.out.println("line is ended:");
       public String test()
       return null;


      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
       <title><h:outputText value="#{messages.Home}" /></title>
       <style type="text/css" media="all">
       @import "style/default/screen.css";
      <div class="sample-container" >
       <rich:tree style="width:300px" value="#{library2.data}" var="item" nodeFace="#{item.type}">
       <rich:treeNode type="brach">
       <h:commandLink value="#{item.name}"
       action="#{library2.test}" style="text-decoration:none" />
       <rich:treeNode type="department1">
       <h:outputText value="#{item.title}" />
       <rich:treeNode type="department2">
       <h:outputText value="#{item.title2}" />
       <rich:treeNode type="employer">
       <h:outputText value="#{item.employername}" />



      now i can get the treeview in mytest.jsp. and i want use the "library2.test" method to update the data of tree. who can give me a hand to write some codes or give me some example. i don't know how to get the data of node form the mytest.jsp and give it ot Library.java.