12 Replies Latest reply on Jun 23, 2009 1:35 PM by nbelaevski

    Tree programmatically creation problem

    kanikman

      In docs creating HtmlTree is very simple. HtmlTee = new HtmlTree(); but how to connect it with tag on the page ? Who knows ? I have tried many options but nothing works.

      So, what is this class for when I can't use it. I can create with HtmlTree and HtmlTreeNode any tree, I can't set icon.

      It seems it should be

      class SomeBean
      {
      HtmlTree tree;
      // Tree creation and so on
      public createTree()
      {
      //create tree and set icons for them
      }
      public HtmlTree getHtmlTree( return tree; }
      }

      and on page

      <rich:tree binding="#{someBean.tree}"/>

      and it should be fine, but it isn't.


      I've spent many time on forum and source code of richfaces demo and internet but I still don't know how to use it.

        • 1. Re: Tree programmatically creation problem
          nbelaevski

          Hi kanikman,

          Yes, it should work fine. What's not working exactly?

          • 2. Re: Tree programmatically creation problem
            kanikman

            This is my bean code:

            htmlTree = new HtmlTree();
            
             htmlTree.setId("MenuTreeId");
             htmlTree.setSwitchType("client");
             htmlTree.setStyle("min-height:100%; min-width:100%; width:100%");
             htmlTree.setReRender("selectedNode");
            
             HtmlTreeNode treeNode = new HtmlTreeNode();
             treeNode.setData("One");
            
             HtmlTreeNode treeNode1 = new HtmlTreeNode();
             treeNode1.setData("Two");
             treeNode.getChildren().add(treeNode1);
            
             htmlTree.getChildren().add(treeNode);
            


            and this on my page:
            <rich:panel>
             <a4j:form>
             <rich:tree binding="#{menuTreeBean.htmlTree}">
             </rich:tree>
             </a4j:form>
             </rich:panel>
            


            The problem is nothing displays.

            • 3. Re: Tree programmatically creation problem
              ilya_shaikovsky

              tree requires dataModel to be created. check please available samples from the beginning.

              • 4. Re: Tree programmatically creation problem
                kanikman

                So, in doc is create HtmlTree = new HtmTree(); and there is any words about dataModel and what to do with the dataModel.

                Which sample, where and so on. I have write that I did not find any sample with using HtmTree interface. I describe my problem cose I did not find any solution.

                Can you point me one sample with HtmlTree interface and where to find it ???

                • 5. Re: Tree programmatically creation problem
                  nbelaevski

                  Add "value" attribute.

                  • 6. Re: Tree programmatically creation problem
                    kanikman

                    You have seen my code. Can You tell me what should I put in value attribute ? htmlTree not work. I don't have in my bean other variables.

                    • 7. Re: Tree programmatically creation problem
                      kanikman

                      Ok, I give up. I'm going to use tomahawk tree. I've wasted 2 days in order to create programmatically simple tree with own icons for every node.

                      When I created tree like with TreeNodeImpl it works, but I can't set up any icon for nodes and when I reloaded page all nodes collapsed every time. When I've created HtmlTree nothing displays.

                      It seems RichFaces tree has more disatvantages than adventages. When you find how to do one thigs other not works and so on.

                      If other component works like tree I'm going to have fear about my project ;).

                      • 8. Re: Tree programmatically creation problem
                        nbelaevski

                         

                        "kanikman" wrote:
                        You have seen my code. Can You tell me what should I put in value attribute ? htmlTree not work. I don't have in my bean other variables.

                        Check livedemo example: http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?c=tree&tab=usage

                        • 9. Re: Tree programmatically creation problem
                          ilya_shaikovsky

                          You just using the component wrong and want us to make samples on all the cases which could rise in JSF world? If you really spent at least small time for exploring samples you should understand what is the dataModel and what is tree value and so on.

                          • 10. Re: Tree programmatically creation problem
                            kanikman

                             

                            "nbelaevski" wrote:
                            "kanikman" wrote:
                            You have seen my code. Can You tell me what should I put in value attribute ? htmlTree not work. I don't have in my bean other variables.

                            Check livedemo example: http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?c=tree&tab=usage


                            So can You tell me in what place in this livedemo example tree is created by HtmlTree interface ? :). I have on my disk richfaces demo source code and there is no code with HtmlTree interaface.

                            • 11. Re: Tree programmatically creation problem
                              ilya_shaikovsky

                              So you could add binding to the component. Create tree Object as you already tried. Define value with valueExpression pointed to the same dataModel. Add nodes and add their children (because node used only for representation definition for different types of nodes and should not be used to add some static node with data as you tried to use).. and so on. Then set needed attributes to the same objects as on the page.

                              Creation component from java code does not differs from page definition from the points of working with needed attributes. But your usage is completely differs with the page usage shown at sample.

                              • 12. Re: Tree programmatically creation problem
                                nbelaevski

                                 

                                "kanikman" wrote:
                                "nbelaevski" wrote:
                                "kanikman" wrote:
                                You have seen my code. Can You tell me what should I put in value attribute ? htmlTree not work. I don't have in my bean other variables.

                                Check livedemo example: http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?c=tree&tab=usage


                                So can You tell me in what place in this livedemo example tree is created by HtmlTree interface ? :). I have on my disk richfaces demo source code and there is no code with HtmlTree interaface.

                                It's created using Facelets tag handlers when the example page is compiled. The idea is to check which attributes are important and set them in Java code.

                                One more example: if you take javax.faces.component.html.HtmlDataTable and create it programmatically, then you'll just get empty table. Fair enough - no "value" is set - no data is rendered; the same applies to rich:tree component (with the one exception - there are special components to describe tree model declaratively, they replace "value" attribute).