1 2 Previous Next 22 Replies Latest reply on Jun 4, 2008 3:45 AM by ilya_shaikovsky

    need help in tree.....

    rajarchu

      Hello all,

      i am generating dynamic tree, the thing is i want to add a link on child node of the tree on clicking it should open in new page. can one help me out ...
      thanks in advance..

        • 1. Re: need help in tree.....
          mamathaks

          Use command link to render your tree nodes.
          ex :
          <rich:treeNode nodeSelectListener="#{bean.handleNodeSelection}">
          <h:commandLink action="#{bean.doSelect}" style="text-decoration: none;color:black;width:60px;overflow:hidden; text-overflow: ellipsis;">
          <h:outputText value="#{opportunity}" />
          </h:commandLink>
          </rich:treeNode>

          Based on the return value from action method, you can navigate to page

          • 2. Re: need help in tree.....
            rajarchu

            Hi mamathaks,
            thanks for ur help, but can u please give bean code so that i can understand more on the action how it works and what do u mean by value=#{opportunity} in output text.

            can you please explain me a little bit more... or can u resend the bean class.


            thanks

            • 3. Re: need help in tree.....
              rajarchu

              Hello All,
              Can anyone help me out in setting up hyperlink to tree leafs...

              I am generating tree dynamically by database.. and i want to a link to tree leafs but i was not able to do so...

              any one has an idea of how to add a link to tree...

              thanks in advance..

              • 4. Re: need help in tree.....
                blabno

                What should open in new page ?
                Personally I would generate link inside treeNode. What stage are you on ? Have you already managed to create the tree model and displayed it, or you are just beginning ?

                • 5. Re: need help in tree.....
                  rajarchu

                  Hi,
                  thanks for reply..
                  no am not at begining, am generating tree and displaying it, and even expanding the tree nodes also, but i want is after expanding the tree node, when i click a child node it should be opened on a different page.
                  thanks

                  • 6. Re: need help in tree.....
                    blabno

                    What should be opened on a new page ?

                    Opening in new page is an issue than try this

                    <a href="..." target="_blank">anyText</a>


                    • 7. Re: need help in tree.....
                      rajarchu

                      Hi Blabno,
                      here is my code.. i cant place href...

                      <h:form id="detailForm">
                       <rich:panel style="height: 100%; width:100%; background-color: #CAC7B7">
                      
                       <rich:tree id="treeFredBean" value="#{treeFredBean.rootNode}" nodeSelectListener="#{treeFredBean.processSelection}"
                       reRender="rootNode1" var="item" ajaxSubmitSelection="true" >
                       </rich:tree>
                       <h:ouputText value="#{treeFredBean.screenName}" id="rootNode1"></h:outputText>
                       </rich:panel>
                       </h:form>
                      
                      backend bean....
                      
                      
                      
                      package cms.web.view.pages;

                      import java.awt.MenuComponent;
                      import java.util.Iterator;

                      import javax.faces.component.html.HtmlCommandLink;
                      import javax.faces.context.FacesContext;
                      import javax.faces.el.MethodBinding;
                      import javax.faces.event.AbortProcessingException;
                      import javax.faces.event.ActionEvent;

                      import net.sf.ehcache.constructs.asynchronous.Command;

                      import org.richfaces.component.UITree;
                      import org.richfaces.event.NodeSelectedEvent;
                      import org.richfaces.event.NodeSelectedListener;
                      import org.richfaces.model.TreeNode;
                      import org.richfaces.model.TreeNodeImpl;

                      import com.sun.faces.taglib.html_basic.OutputLinkTag;
                      import com.sun.webui.jsf.component.Hyperlink;

                      public class tree_fredBean {

                      private TreeNode rootNode = null;
                      private String nodeTitle;

                      public void setNodeTitle(String nodeTitle){
                      this.nodeTitle = nodeTitle;
                      }
                      public String getNodeTitle(){
                      return this.nodeTitle;
                      }

                      public void setRootNode(TreeNode rootNode) {
                      this.rootNode = rootNode;
                      }

                      public TreeNode getRootNode() {
                      if (rootNode == null) {
                      buildTree();
                      }

                      return rootNode;
                      }

                      private void buildTree() {
                      rootNode = new TreeNodeImpl();
                      TreeNodeImpl mainNode1 = new TreeNodeImpl();
                      TreeNodeImpl mainNode2 = new TreeNodeImpl();
                      TreeNodeImpl childNode1 = new TreeNodeImpl();
                      TreeNodeImpl childNode2 = new TreeNodeImpl();
                      TreeNodeImpl childNode3 = new TreeNodeImpl();
                      mainNode1.setData("Parent");
                      mainNode2.setData("GrandParent");
                      childNode1.setData("Tom");
                      mainNode1.addChild("Tom", childNode1);
                      childNode2.setData("Jerry");
                      mainNode1.addChild("Jerry", childNode2);
                      childNode3.setData("Pat");
                      mainNode2.addChild("Pat", childNode3);
                      rootNode.addChild("Parent", mainNode1);
                      rootNode.addChild("GrandParent", mainNode2);

                      }
                      private String str = null;

                      public String getStr() {
                      return str;
                      }
                      public void setStr(String str) {
                      this.str = str;
                      }
                      public void processSelection(NodeSelectedEvent event){
                      //throws AbortProcessingException {
                      // TODO Auto-generated method stub
                      UITree ut = (UITree) event.getComponent();
                      nodeTitle = (String) ut.getRowData();

                      }

                      }



                      now can u please tell me how to do when i click on child nodes i want to dispaly some website in different page....

                      thanks

                      • 8. Re: need help in tree.....
                        rajarchu

                        anyone has any clue how to add link to a child node of a tree..
                        thanks

                        • 9. Re: need help in tree.....
                          nbelaevski

                          Hello,

                          You should use nested rich:treeNode components to customize presentation for concrete node type, see example here: http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?c=tree

                          Example code:

                          <h:form id="detailForm">
                           <rich:panel style="height: 100%; width:100%; background-color: #CAC7B7">
                          
                           <rich:tree id="treeFredBean" value="#{treeFredBean.rootNode}" nodeSelectListener="#{treeFredBean.processSelection}"
                           reRender="rootNode1" var="item" ajaxSubmitSelection="true" nodeFace="#{item.leaf ? 'link' : null}">
                          
                           <rich:treeNode type="link"><h:outputLink target="_blank" value="#{item.url}"><h:outputText value="#{item.text}" /></h:outputLink>
                           </rich:treeNode>
                           </rich:tree>
                           <h:ouputText value="#{treeFredBean.screenName}" id="rootNode1"></h:outputText>
                           </rich:panel>
                           </h:form>


                          And node implementation code:
                          package org.richfaces;
                          
                          import org.richfaces.model.TreeNodeImpl;
                          
                          public class MyTreeNodeImpl extends TreeNodeImpl {
                          
                           private String text;
                           private String url;
                          
                           public Object getData() {
                           return this;
                           }
                          
                           public void setData(Object data) {
                           throw new UnsupportedOperationException();
                           }
                          
                           public MyTreeNodeImpl(String text, String url) {
                           super();
                           this.text = text;
                           this.url = url;
                           }
                          
                           public String getText() {
                           return text;
                           }
                          
                           public String getUrl() {
                           return url;
                           }
                          
                          }
                          


                          Please note getData() method that's returning this. That's needed because RichFaces versions prior to 3.2.1 didn't have treeNodeVar attribute of rich:tree implemented, so in this case TreeNode itself is represented as data. If you are using 3.2.1 you can make the code a bit simpler by making use of treeNodeVar attribute to get access to the current TreeNode instance



                          • 10. Re: need help in tree.....
                            rajarchu

                            Hi Nbelaevski,

                            I am using 3.2.0.SR1 version, but still am not able to get, i want to ask u one more question MyTreeNodeImpl is in my case tree_fredBean right. if i did like that then i got java.lang.InstantiationException:
                            and if used it as a seperate class then how that class is linked with tree_fredBean class and what is item.leaf here am getting excetion for that too... can u explain a little more..
                            thanks in advace

                            • 11. Re: need help in tree.....
                              rajarchu

                              Hi Nbelaevski,
                              Still its not working can please tell me how to do using my code.
                              thanks in advance

                              • 12. Re: need help in tree.....
                                rajarchu

                                Hello Nbelaevski,
                                Can you please help me out in this case..
                                thanks

                                • 13. Re: need help in tree.....
                                  rajarchu

                                  hello all.. any one ther.. to help me out.. in getting link to child node for a tree..
                                  thanks in advance

                                  • 14. static tree
                                    ice_casa

                                    i would create a satatic tree :
                                    my jsf :
                                    <rich:panel style="height: 100%; width:100%; background-color: #CAC7B7">

                                    <rich:tree style="width:200px" styleClass="align-center-margin" mode="ajax" itemClass="white"
                                    hoveredItemClass="blue">
                                    <rich:treeNode label="artist" iconLeaf="/images/tree/singer.gif" icon="/images/tree/singer.gif">
                                    <f:param name="current" value="Company1"/>
                                    </rich:treeNode>
                                    <rich:treeNode label="album" iconLeaf="/images/tree/disc.gif" icon="/images/tree/disc.gif">
                                    <f:param name="current" value="Company2"/>
                                    </rich:treeNode>
                                    <rich:treeNode label="song" iconLeaf="/images/tree/song.gif" icon="/images/tree/song.gif">
                                    <f:param name="current" value="Company3"/>
                                    </rich:treeNode>
                                    </rich:tree>
                                    </rich:panel>



                                    the error is :

                                    org.richfaces.component.EnclosingFormRequiredException: class org.richfaces.component.html.HtmlTree (id="j_id96") did not find parent form. org.richfaces.component.util.FormUtil.throwEnclFormReqExceptionIfNeed(FormUtil.java:45)
                                    org.richfaces.renderkit.html.TreeRe

                                    1 2 Previous Next