3 Replies Latest reply on Apr 18, 2007 10:10 AM by Alex

    Tree Sample - Duplicate component ID '_id1' found in view.

    sateesh kumar Newbie

      Hi All,

      I am trying to create a Simple Drag and Drop Tree and when i add Elements to the Root Element and the Child Elements i have added to the Root are leaf Nodes and they are getting displayed with Folder Icon. And when i try to expand any of these Child Nodes i am getting an Error..

      And all these Child Nodes has the same Display Text ( Root Node)

      Code i am using is:

      I have a Basic DragDrop Tree Node . Still in the priliminary stage ..

       package org.richfaces;
      
      import java.io.IOException;
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.LinkedHashMap;
      import java.util.Map;
      
      import javax.faces.FacesException;
      import javax.faces.component.UIComponent;
      import javax.faces.event.FacesEvent;
      
      import org.ajax4jsf.dnd.event.DragEvent;
      import org.ajax4jsf.dnd.event.DropEvent;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.richfaces.component.ListRowKey;
      import org.richfaces.component.TreeNode;
      import org.richfaces.component.TreeNodeImpl;
      import org.richfaces.component.UITree;
      import org.richfaces.component.UITreeNode;
      import org.richfaces.component.events.NodeExpandedEvent;
      import org.richfaces.component.events.NodeSelectedEvent;
      
      public class DPADragDropTree {
      
      
       static Log log = LogFactory.getLog(DPADragDropTree.class);
      
       private TreeNode selectedNode = null;
      
       private UITree uiTree;
      
       private TreeNode rootNode = null;
      
       private Map nodeToTreeNodeMap = null;
      
       private Map selectedNodeChildren = new LinkedHashMap<TreeNode,Integer>();
      
       private String expandPath;
      
       private Object dragValue;
      
       private String pathToExpand;
      
       private boolean dragOn;
      
      
       public DPADragDropTree(){
       super();
       dragOn = true;
       nodeToTreeNodeMap = new HashMap<Node,TreeNode>();
       }
      
      
      
       // Tree Operations and Events
      
       public void onSelect(NodeSelectedEvent event) {
       log.info("Node selected: " + getTree(event).getRowKey());
       if (getTree(event).getTreeNode() != null) {
       selectedNode = getTree(event).getTreeNode();
       refreshSelectedNode();
       }
       }
      
       public void onExpand(NodeExpandedEvent event) {
       UITree tree = getTree(event);
       log.info("Node "
       + (tree.isExpanded() ? "expanded" : "collapsed") + " "
       + tree.getRowKey());
       }
      
       public String expand() {
       if (expandPath != null && expandPath.length() != 0) {
       try {
       uiTree.queueNodeExpand(new ListRowKey(expandPath));
       }
       catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       }
      
       return null;
       }
      
       public String collapseAll() throws IOException {
       this.uiTree.queueCollapseAll();
       return null;
       }
      
       public String expandAll() {
       try {
       this.uiTree.queueExpandAll();
       } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       }
       return null;
       }
      
      
       public Map getSelectedNodeChildren() {
       return selectedNodeChildren;
       }
      
       public void setSelectedNodeChildren(Map selectedNodeChildren) {
       this.selectedNodeChildren = selectedNodeChildren;
       }
      
      
       public void processDrop(DropEvent dropEvent) {
       log.info("Should be printed twice per event!!!");
       log.info(dropEvent);
       log.info("DragValue: " + dropEvent.getDragValue());
       log.info("DropValue: " + dropEvent.getDropValue());
       /*
       log.info("Drag row data: "
       + getTree(dropEvent).getRowData(dropEvent.getDragValue()));
       log.info("Drop row data: "
       + getTree(dropEvent).getRowData(dropEvent.getDropValue()));
       log.info("+++++");
       */
       log.info("Bean.processDrop()");
       this.dragValue = dropEvent.getDragValue();
      
       }
      
       public String expandNode() {
       String pathToExpand = getPathToExpand();
       if (pathToExpand != null && pathToExpand.trim().length() != 0) {
       try {
       (getUiTree()).queueNodeExpand(new ListRowKey(
       pathToExpand));
       } catch (IOException e) {
       throw new FacesException(e);
       }
       }
      
       return null;
       }
      
      
      
       public void processDrag(DragEvent dragEvent) {
       log.info("Bean.processDrag()");
       }
      
       private UITree getTree(FacesEvent event) {
       UIComponent component = event.getComponent();
       if (component instanceof UITree) {
       return ((UITree) component);
       }
      
       if (component instanceof UITreeNode) {
       return ((UITree) component.getParent());
       }
      
       return null;
       }
      
       private void refreshSelectedNode() {
       selectedNodeChildren.clear();
       if (selectedNode != null) {
       Iterator iter = selectedNode.getChildren();
       int i = 0;
       while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       selectedNodeChildren.put(((TreeNode) entry.getValue()).getData(), Integer.toString(i++));
       }
       }
       }
       // Setter and Getters for the Data Members..
      
      
       /**
       *
       * @return
       */
      
      
       public Map getNodeToTreeNodeMap() {
       return nodeToTreeNodeMap;
       }
      
      
      
      
       public void setNodeToTreeNodeMap(Map nodeToTreeNodeMap) {
       this.nodeToTreeNodeMap = nodeToTreeNodeMap;
       }
      
      
      
      
       public TreeNode getRootNode() {
       return rootNode;
       }
      
      
      
      
       public void setRootNode(TreeNode rootNode) {
       this.rootNode = rootNode;
       }
      
      
      
      
       public TreeNode getSelectedNode() {
       return selectedNode;
       }
      
      
      
      
       public void setSelectedNode(TreeNode selectedNode) {
       this.selectedNode = selectedNode;
       }
      
      
      
      
       public UITree getUiTree() {
       return uiTree;
       }
      
      
      
      
       public void setUiTree(UITree uiTree) {
       this.uiTree = uiTree;
       }
      
      
       public String getExpandPath() {
       return expandPath;
       }
      
      
      
       public void setExpandPath(String expandPath) {
       this.expandPath = expandPath;
       }
      
       public Object getDragValue() {
       return dragValue;
       }
      
      
      
       public void setDragValue(Object dragValue) {
       this.dragValue = dragValue;
       }
      
      
      
       public String getPathToExpand() {
       return pathToExpand;
       }
      
      
      
       public void setPathToExpand(String pathToExpand) {
       this.pathToExpand = pathToExpand;
       }
      
       public boolean isDragOn() {
       return dragOn;
       }
      
       public void setDragOn(boolean dragOn) {
       this.dragOn = dragOn;
       }
      }
      
      


      And my Managed Bean is

       public class FormatTreeBean {
      
       DPADragDropTree dragDropTree =null;
      
       public FormatTreeBean(){
      
       dragDropTree = new DPADragDropTree();
       initTree(dragDropTree);
      
      
       }
      
      
       public void setDragDropTree(DPADragDropTree dragDropTree) {
       this.dragDropTree = dragDropTree;
       }
      
       public DPADragDropTree getDragDropTree() {
       return dragDropTree;
       }
      
       public void initTree(DPADragDropTree dragDropTree){
      
       TreeNodeImpl rootNode = new TreeNodeImpl();
       rootNode.setData("Root Node");
      
       for(int i=0;i<10;i++){
       TreeNodeImpl childNode = new TreeNodeImpl();
       childNode.setData(" Node "+i);
       childNode.setParent(rootNode);
       rootNode.addChild(new Integer(i), rootNode);
       }
      
       dragDropTree.setRootNode(rootNode);
      
       }
      
      
      }
      


      And my JSP Page is:

       <f:view>
       <a4j:outputPanel ajaxRendered="true">
       <h:messages />
       </a4j:outputPanel>
      
       <h:form>
      
       <dnd:dragIndicator id="treeIndicator">
       <f:facet name="single">
       <f:verbatim>{marker} <br /> {treeParam} <br /> {nodeParam}</f:verbatim>
       </f:facet>
       </dnd:dragIndicator>
      
       <rich:tree
       id="DPAFormatTree"
       value="#{FormatTreeBean.dragDropTree.rootNode}"
       var="node"
       nodeFace="#{data.name != 'param-value' ? 'input' : 'text'}"
       changeExpandListener="#{FormatTreeBean.dragDropTree.onExpand}"
       nodeSelectListener="#{FormatTreeBean.dragDropTree.onSelect}"
       binding="#{FormatTreeBean.dragDropTree.uiTree}"
       onselected="window.status='selectedNode: '+event.selectedNode"
       onexpand="window.status='expandedNode: '+event.expandedNode"
       oncollapse="window.status='collapsedNode: '+event.collapsedNode"
       ajaxSubmitSelection="true"
       reRender="outputText, selectOneListbox"
       preserveModel="none"
       dragIndicator="treeIndicator"
       immediate="false"
       acceptedTypes="file1"
       dragType="#{FormatTreeBean.dragDropTree.dragOn ? 'file1' : ''}"
       dropListener="#{FormatTreeBean.dragDropTree.processDrop}">
      
       </rich:tree>
       </h:form>
       </f:view>
      


      Another thing i couldn't figure out is setting the value for nodeFace. if i use

      
      value ="{#node.data}"
      
       I am getting the Error:
      
      javax.faces.el.PropertyNotFoundException: Error getting property 'data' from bean of type java.lang.String
      
      


      As the above should be resolved to

      nodeFace ="#{FormatTreeBean.dragDropTree.rootNode.data}"

      rootNode is of Type TreeNode and it has getData() method ..I am unable to figure out why
      the type is java.lang.String as the error suggested..


      Thanks
      Sateesh

        • 1. Re: Tree Sample - Duplicate component ID '_id1' found in vie
          Dustin Norlander Apprentice

          Not sure if this is your problem, but this does not look right:

          var="node"
          nodeFace="#{data.name != 'param-value' ? 'input' : 'text'}"
          


          I believe it should be:

          var="node"
          nodeFace="#{node.name != 'param-value' ? 'input' : 'text'}"
          


          • 2. Re: Tree Sample - Duplicate component ID '_id1' found in vie
            sateesh kumar Newbie

            Hi,

            Thanks for your response..

            I made the change and now i am still getting the same exception..

             nodeFace="#{node.name != 'param-value' ? 'input' : 'text'}"
            


             org.apache.jasper.JasperException: javax.faces.el.PropertyNotFoundException: Error getting property 'name' from bean of type java.lang.String
            


            Then instead of using the var name 'node' i used

             nodeFace="#{FormatTreeBean.dragDropTree.rootNode.data}"
            

            And now i am getting the exception..

             java.lang.IllegalStateException: Duplicate component ID '_id1' found in view.
             at com.sun.faces.application.StateManagerImpl.checkIdUniqueness(StateManagerImpl.java:201)
             at com.sun.faces.application.StateManagerImpl.checkIdUniqueness(StateManagerImpl.java:204)
             at com.sun.faces.application.StateManagerImpl.saveSerializedView(StateManagerImpl.java:97)
             at org.ajax4jsf.framework.ajax.AjaxStateManager.saveSerializedView(AjaxStateManager.java:90)
             at com.sun.faces.taglib.jsf_core.ViewTag.doAfterBody(ViewTag.java:189)
             at org.apache.jsp.pages.tree_005fsample_jsp._jspx_meth_f_005fview_005f0(tree_005fsample_jsp.java:160)
             at org.apache.jsp.pages.tree_005fsample_jsp._jspService(tree_005fsample_jsp.java:107)
             at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
             at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
             at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
             at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
             at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:687)
             at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
             at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
             at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
             at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:346)
             at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:152)
             at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
             at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:229)
             at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
             at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
             at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:137)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:214)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
             at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
             at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
             at java.lang.Thread.run(Thread.java:595)
            


            Thanks
            Sateesh

            • 3. Re: Tree Sample - Duplicate component ID '_id1' found in vie
              Alex Newbie

              Hi,
              look at your rendered HTML Code and look where you have components with _id1 in it. Then set the ID-tag within that component.
              I had got this error several times too, but since I set the ID-tag in every rich or a4j UIComponent I don't have this problem anymore.

              Cu
              Alex