1 Reply Latest reply on Nov 2, 2008 11:52 AM by Nick Belaevski

    Building the HtmlTree at runtime

    Rafael Chiarinelli Newbie

      Hi All, I'm developing in an HtmlTree, using RichFaces and Seam, which is generated dynamically. But, my page doesn't show the htmlTree. Here is the snippet from JSP and the ManagedBean:

      JSP:

      <h:form id="treeMenuForm">
      <rich:tree id="tree" binding="#{htmlTree}"/>
      </h:form>

      ManagedBean:

      @Out(required = false) private HtmlTree htmlTree;

      @Begin(join = true)
      @Factory(value = "htmlTree")
      public HtmlTree getHtmlTree() throws ValidationException {
      //HtmlTree
      Application application = FacesContext.getCurrentInstance().getApplication();
      UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
      this.htmlTree = (HtmlTree) application.createComponent(HtmlTree.COMPONENT_TYPE);
      this.htmlTree.setId(viewRoot.createUniqueId());
      this.htmlTree.setStyle("width:400px");
      this.htmlTree.setRendered(true);
      this.htmlTree.setIcon("/image/Treeview/Treeview_folder_opened_A.gif");
      this.htmlTree.setIconCollapsed("/image/Treeview/Treeview_plus_last_node.gif");
      this.htmlTree.setIconExpanded("/image/Treeview/Treeview_minus_last_node.gif");
      this.htmlTree.setIconLeaf("/image/Treeview/Treeview_page_A.gif");
      this.htmlTree.setSwitchType("server");
      this.htmlTree.setAdviseNodeOpened(application.createMethodBinding("#{mainViewAction.expanded}", new Class[0]));
      this.htmlTree.setChangeExpandListener(application.createMethodBinding("#{mainViewAction.changeExpandListener}", new Class[0]));
      this.htmlTree.getChildren().add(this.buildNodes(this.treeMenu));
      }

      private HtmlTreeNode buildNodes(GBNode[] nodes) {
      Application application = FacesContext.getCurrentInstance().getApplication();
      UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
      HtmlTreeNode htmlTreeNode = null;
      HtmlGraphicImage image = null;
      HtmlOutputText text = null;
      for (int cont = 0; cont < nodes.length; cont++) {
      GBNode item = nodes[cont];
      htmlTreeNode = (HtmlTreeNode) application.createComponent(HtmlTreeNode.COMPONENT_TYPE);
      htmlTreeNode.setId(viewRoot.createUniqueId());
      htmlTreeNode.setRendered(true);
      // Imagem do nó
      image = (HtmlGraphicImage) application.createComponent(HtmlGraphicImage.COMPONENT_TYPE);
      image.setId(viewRoot.createUniqueId());
      image.setHeight("18");
      image.setWidth("15");
      image.setStyleClass("textCurrentTreeview");
      htmlTreeNode.getFacets().put("icon", image);
      //Texto do nó
      text = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
      text.setId(viewRoot.createUniqueId());
      text.setValue(item.getText());
      text.setStyleClass("textCurrentTreeview");
      htmlTreeNode.getChildren().add(text);
      if (item.getChildren()!=null && item.getChildren().length > 0) {
      htmlTreeNode.getChildren().add(this.buildNodes(item.getChildren()));
      }
      }
      return htmlTreeNode;
      }

      Any ideas?

      tks

      Rafael