13 Replies Latest reply on Jun 24, 2015 3:55 AM by michpetrov

    DuplicateIdException while upgrading <rich:tree>

    kkn

      Hi,

       

      While upgrading richfaces tree from 3x to 4x version, I have followed the steps

      1. Created a new class which extends the TreeNodeImpl class.

       

      package com.qualcomm.mysource.model;

       

      import org.richfaces.model.TreeNode;

      import org.richfaces.model.TreeNodeImpl;

       

      public class TreeNodeImplExtended extends TreeNodeImpl {

        private Object data;

        private TreeNode parent;

       

        public Object getData() {

        return data;

        }

        public void setData(Object data) {

        this.data = data;

        }

        public TreeNode getParent() {

        return parent;

        }

        public void setParent(TreeNode parent) {

        this.parent = parent;

        }

      }

       

      2. Modified the attributes as per the upgrade examples

      <rich:tree

             id="accessTree"

             toggleType="client"

             binding="#{richBean.accessTree}" 

             value="#{richBean.accessTreedata}"

             var="d"

             style="margin: 10px;width:300px"

        >

             <rich:treeNode

                  id="accessTreenode"

                  rendered="true"

                  highlightedClass="basefont"

             >

                  <h:outputText value="#{d.data.label}"/></font>

           </rich:treeNode>

      </rich:tree>

       

      However, when I am loading the page, I am getting duplicateIdException. When I compared the tree ids with the previous version, it looks like

      accessForm:accessTree:1:home:accessTreeNode

      Now, in the error, I am seeing the ids as accessForm:accessTree:accessTreeNode.

       

      I am wondering why the keys "1" and "home" are not showing up in new <rich:tree>.

       

      I have not modified anything in my existing class part from TreeNodeImpl class to TreeNodeImplExtended class.

       

      Can anyone please help if I am missing anything with the new richfaces tree implementation.

       

      Thank you!

        • 1. Re: DuplicateIdException while upgrading <rich:tree>
          michpetrov

          Hi,

           

          the ids should be generated from the keys you put in the tree. Can you show the code that creates the tree?

          • 2. Re: DuplicateIdException while upgrading <rich:tree>
            kkn

            Hi,

             

            I have been playing around with the code and found that the property binding is causing the problem. Removing that attribute shows the tree but I am not very clear why it is causing the problem as I see that binding is still valid in 4x version. Can you please help in understanding the problem?

             

            Thank you!

             

            XHTML Tree is

             

            <rich:tree

              id="frontOfficeTree" binding="#{richBean.frontOfficetree}"

              toggleType="client"

              value="#{richBean.fronOfficeTreeData}"

              var="d"

              style="margin: 10px;width:300px"

              >

              <rich:treeNode

              id="frontOfficeTreenode"

              rendered="true"

              highlightedClass="basefont"

              >

              <font class="headerfont"><h:outputText value="#{d.data.name}"/></font>

              </rich:treeNode>

              </rich:tree>

             

             

            My backing bean is

            package com.kkn.bean;

             

            import org.richfaces.component.UITree;

            import org.richfaces.model.TreeNode;

            import com.kkn.model.TreeNodeImplExtended;

            import com.kkn.model.AccessNodeData;

             

             

            @SuppressWarnings("unchecked")

            public class AccessBackingBean {

              private transient UITree accessTree;

              TreeNodeImplExtended accessTreedata;

             

              public void init() {

              buildTree();

              }

             

             

              private void buildTree() {

              accessTreedata = new TreeNodeImplExtended();

              TreeNodeImplExtended child = new TreeNodeImplExtended();

              child.setData(new AccessNodeData("Home"));

              TreeNodeImplExtended childBooks = new TreeNodeImplExtended();

              childBooks.setData(new AccessNodeData("Books"));

              TreeNodeImplExtended childMusic = new TreeNodeImplExtended();

              childMusic.setData(new AccessNodeData("Music"));

              TreeNodeImplExtended childBlogs = new TreeNodeImplExtended();

              childBlogs.setData(new AccessNodeData("Blogs"));

              TreeNodeImplExtended childContact = new TreeNodeImplExtended();

              childContact.setData(new AccessNodeData("Contact Us"));

              child.addChild("books", childBooks);

              child.addChild("music", childMusic);

              child.addChild("blogs", childBlogs);

              child.addChild("contact", childContact);

              accessTreedata.addChild("home", child);

              }

             

            public TreeNode getAccessTreedata() {

              return this.accessTreedata;

              }

             

            public UITree getAccessTree() {

              return accessTree;

              }


            public void setFrontOfficetree(UITree accessTree) {

              this.accessTree = accessTree;

              }

            }

             

            TreeNodeImplExtended.java is in first post.

            AccessNodeData.java has single property called name.

             


            • 3. Re: DuplicateIdException while upgrading <rich:tree>
              kkn

              Hi,

               

              I have another issue with the tree. Even though the duplicate id issue is resolved after removing the binding attribute, it is not showing as tree. It is shown as list of items one by one as shown below. Books, Music, Blogs and Contact Us should come under Home. Also, there is no more the default image TreePlusImage shown up.

               

              RichfacesTree.jpg

              • 4. Re: DuplicateIdException while upgrading <rich:tree>
                michpetrov

                Looks like the CSS files are missing, do you have <h:head> on your page? (Btw. <font> has been a deprecated element for a long time, don't use it.)

                 

                Not sure why the binding caused an error but if that's your actual code you should be getting an error anyway, your setter and getter for the tree are named differently.

                • 5. Re: DuplicateIdException while upgrading <rich:tree>
                  kkn

                  I do have head section. And which CSS file you are talking about.. Is there a richfaces specific CSS file? I am yet to clean the code I first wanted to make it work with least changes while upgrade.

                   

                  Oh, I just manipulated the code as it was too much of actual code. So, but even if I somehow am able to get rid of duplicate id exception, I am not able to see the tree properly, as shown in my above example. Books, Music, Blogs and Contact Us should come under Home.

                  • 6. Re: DuplicateIdException while upgrading <rich:tree>
                    michpetrov

                    There should be a file named tree.ecss or packed.css if you're using resource optimization.

                    • 7. Re: DuplicateIdException while upgrading <rich:tree>
                      kkn

                      Hi,

                       

                      I am not using resource optimization. I have missed your point of <h:head> in previous comment. I have <head> tag instead of <h:head> tag. I replaced the <head> tag with <h:head> tag and it worked!

                      However, it would be really great if you can help me in understanding how this is different from 3x implementation.


                      Thank you!

                      • 8. Re: DuplicateIdException while upgrading <rich:tree>
                        michpetrov

                        This is more of a JSF 1.2 vs JSF 2 situation since h:head is not a RichFaces tag, I guess there were some changes in resource handling (I have little experience working with RF 3.x). In JSF 2 resources have a target location (body or head) but the target has to be a component, <head> is just a piece of text for JSF.

                        • 9. Re: DuplicateIdException while upgrading <rich:tree>
                          kkn

                          Hi,

                           

                          Thank you for the reply!

                           

                          With <h:head> tag, the richfaces resources are now loading fine. However, I am now struggling with the default node icons.

                           

                          As per the simple example given here example 12.1 (Chapter 12. Trees), the parent node is holding iconFolder image and children nodes are showing documentIcon. I assume these are default icons provided by richfaces when icons are not explicitly provided. However, for me, parent nodes are showing folderIcon properly but children nodes are also showing up with folderIcon. I do not want to add another resource (document icon image) if it is by default provided by richfaces but I am not sure why document icon is not showing up for me. I have tried the same example but it is still showing folderIcon for me for children nodes Also, the expand/collapse icons are not as per the example (I am seeing plus icon).

                           

                          Also, I have expand all functionality as mentioned in my main discussion and you suggested to traverse the whole tree again, do you have a better solution instead of traversing the whole tree and setting the expanded property for each node?. What I have noticed on expand/collapse is only the CSS classes of the nodes are modified, so, I can handle the expandAll/collapseAll in client side using javascript and resetting the classes everytime of all the nodes on expand all.

                          • 10. Re: DuplicateIdException while upgrading <rich:tree>
                            kkn

                            Hi,

                             

                            I was initially trying a sample example outside of my application and after adding h:head tag, it worked fine.

                            After integrating the new rich:tree in my application and adding h:head tag, all the CSS of my application is being overridden by skinning.ecss richfaces CSS.

                             

                            Is there a way to avoid this apart from adding important for CSS properties as I have huge customized CSS for my application?

                            • 11. Re: DuplicateIdException while upgrading <rich:tree>
                              michpetrov

                              Add this to your web.xml

                              <context-param>
                                  <param-name>org.richfaces.enableControlSkinning</param-name>
                                  <param-value>false</param-value>
                              </context-param>
                              

                              it will disable skinning for buttons, inputs and the like (i.e. it will remove skinning.ecss). It's in the docs (and if you're upgrading to RF 4.5.X you shouldn't be looking at the docs for 4.0.0).

                               

                              If your seeing folders in front of leaves then the tree renderer is not aware that those are leaves, you're not setting it up in your code as far as I can see, by default TreeNodeImpl is not a leaf. (The important method is isLeaf(), either override it or use a constructor that sets up the value).

                               

                              If you only want to expand the tree on the client side then yes you can use JavaScript (there are JavaScript methods for expanding and collapsing), I thought you were looking for a way to make the UITree expand on server side.

                              • 12. Re: DuplicateIdException while upgrading <rich:tree>
                                kkn

                                Hi,

                                 

                                Thank you for the reply!!

                                 

                                The <context-param> worked and now it is no more overriding my CSS!

                                 

                                However, after adding <h:head>, I could see the below files getting loaded

                                jquery.js, richfaces.js and richfaces-queue.js. What I am more worried about is, I already have a jQuery version in my project and a different version is getting loaded through richfaces. Is there a way and will be okay if I can stop jQuery to get downloaded?

                                 

                                Also, can you please explain how can I use server side expand/collapse functionality as I tried using UITree and binding property but it was throwing the base issue of duplicateIdException.

                                 

                                Thank you!

                                • 13. Re: DuplicateIdException while upgrading <rich:tree>
                                  michpetrov

                                  You can use your own version of jQuery if you want to as described in our docs. As for the tree expansion, you can look the component up instead of using binding - UIComponent.findComponent