1 Reply Latest reply on Oct 31, 2008 7:34 PM by rchiarinelli.rchiarinelli.gmail.com

    Generating a htmlTree dynamically

    rchiarinelli.rchiarinelli.gmail.com


      Hi All,

         I'm developing a JSP, using RichFaces and Seam, which contains a htmlTree that 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 {
              if (this.htmlTree == null) {
                  //HtmlTree
                  Application application = FacesContext.getCurrentInstance().getApplication();
                  this.htmlTree = (HtmlTree) application.createComponent(HtmlTree.COMPONENT_TYPE);
                  htmlTree.setStyle("width:300px");
                  htmlTree.setRendered(true);
                  htmlTree.setIcon("/image/Treeview/Treeview_folder_opened_A.gif");
                  htmlTree.setIconCollapsed("/image/Treeview/Treeview_plus_last_node.gif");
                  htmlTree.setIconExpanded("/image/Treeview/Treeview_minus_last_node.gif");
                  htmlTree.setIconLeaf("/image/Treeview/Treeview_page_A.gif");
                  htmlTree.setSwitchType("server");
                  htmlTree.setAdviseNodeOpened(application.createMethodBinding(
                           "#{mainViewAction.expanded}", new Class[0]));
                  htmlTree.setChangeExpandListener(application.createMethodBinding(
                          "#{mainViewAction.changeExpandListener}", new Class[0]));
                  htmlTree.getChildren().add(this.buildNodes(this.treeMenu));

              }
              return this.htmlTree;
          }

          /**
           *
           * @param nodes
           * @return
           */
          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 = new HtmlTreeNode();           
                  htmlTreeNode.setId(viewRoot.createUniqueId());
                  htmlTreeNode.setRendered(true);
      //            Imagem do nó
                  image = (Ht
      mlGraphicImage) application.createComponent(HtmlGraphicImage.COMPONENT_TYPE);
                  image = new HtmlGraphicImage();           
                  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 = new HtmlOutputText();           
                  text.setId(viewRoot.createUniqueId());
                  text.setValue(item.getText());
                  text.setStyleClass("textCurrentTreeview");
                  htmlTreeNode.getChildren().add(text);
              }
              return htmlTreeNode;
          }


      Can anyone help me?

        • 1. Re: Generating a htmlTree dynamically
          rchiarinelli.rchiarinelli.gmail.com

          Sorry people. The correct style for the post:


          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;
              }