3 Replies Latest reply on Jul 21, 2009 8:09 AM by Yogesh Bhardwaj

    ClassCastException and IllegalStateException in tree manipul

    Yogesh Bhardwaj Newbie

      Hello fellows,

      RichFaces version - 3.1.0

      I am trying to dynamically add nodes to a tree, using the following code:

      <a4j:outputPanel id="myAjaxPanel">
       <fieldset class="fieldset" style="width:85%; height:150px">
       <legend>My Tree</legend>
       <rich:tree style="width:500px" id="ifTree" switchType="client" value="#{myBackingBean.IPSDetailData.dataObject.myRootNode}" var="myRootNode"
       ajaxSubmitSelection="true" nodeSelectListener="#{myBackingBean.processNodeSelection}">
       <rich:treeNode>
       <h:outputText value="#{myRootNode}"/>
       </rich:treeNode>
       </rich:tree>
       </fieldset>
      </a4j:outputPanel>
      


      The new child gets added to the node that is selected in the tree, and every time I add a new node, I refresh 'myAjaxPanel' and the tree looks fine.

      But whenever I just refresh the page or access the page from somewhere else, after a node selection, I get the following exception. It works fine if I don't select any node and then hit refresh.

      java.lang.ClassCastException: java.lang.Integer incompatible with org.richfaces.model.StackingTreeModel$Key
       at org.richfaces.model.StackingTreeModel.doSetupKey(StackingTreeModel.java:129)
       at org.richfaces.model.StackingTreeModel.setupKey(StackingTreeModel.java:167)
       at org.richfaces.model.StackingTreeModel.setRowKey(StackingTreeModel.java:460)
       at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:319)
       at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:299)
       at org.richfaces.renderkit.TreeRendererBase.encodeSelectionStateInput(TreeRendererBase.java:481)
       at org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:214)
       at org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:237)
       at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:135)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:754)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
       at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:79)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:735)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:244)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1095)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1036)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
       at com.logistics.ucl.security.worksession.WorkSessionAuditServletFilter.doFilter(WorkSessionAuditServletFilter.java:116)
       at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:832)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:679)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:565)
       at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
       at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
       at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:748)
       at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
       at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
       at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
       at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
       at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
       at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
       at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
       at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
       at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
       at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
      



      I tried making the following change in org.richfaces.model.StackingTreeModel to get around the issue, but now I get the following exception:

      java.lang.IllegalStateException: No tree element available or row key not set!
       at org.richfaces.model.StackingTreeModel.getCurrentModel(StackingTreeModel.java:79)
       at org.richfaces.model.VisualStackingTreeModel.getComponent(VisualStackingTreeModel.java:37)
       at org.richfaces.component.UITree.getNodeFacet(UITree.java:241)
       at org.richfaces.component.UITree.dataChildren(UITree.java:415)
       at org.ajax4jsf.component.UIDataAdaptor.restoreChildState(UIDataAdaptor.java:857)
       at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:325)
       at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:299)
       at org.richfaces.renderkit.TreeRendererBase.encodeSelectionStateInput(TreeRendererBase.java:481)
       at org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:214)
       at org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:237)
       at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:135)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:754)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
       at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:79)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:735)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:244)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1095)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1036)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
       at com.logistics.ucl.security.worksession.WorkSessionAuditServletFilter.doFilter(WorkSessionAuditServletFilter.java:116)
       at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
       at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:832)
       at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:679)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:565)
       at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
       at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
       at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:748)
       at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
       at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
       at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
       at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
       at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
       at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
       at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
       at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
       at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
       at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
       at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
      


      I am using <t:saveState... /> to maintain root node in a java.util.Map object in the session, but I'm setting this Map to an empty object when the root node is null. The tree renderer still thinks that there is a selected node, and hence the error. Is there a way I can set everything to null in the tree component when there is no root node?

      I would really appreciate any help with this.

      Thanks

        • 2. Re: ClassCastException and IllegalStateException in tree man
          Yogesh Bhardwaj Newbie

          Thanks for the reply Nick,

          We have custom code that extends ajax4jsf, and one such example is org.ajax4jsf.application.AjaxStateManager. I am getting the following exception using 3.1.6 (our code is using TreeStrutureNode and looks like it's not there in 3.1.6):

          java.lang.NoClassDefFoundError: org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode
          


          I forgot to mention my code change in base 3.1.0. In org.richfaces.model.StackingTreeModel, I changed the following:

          protected StackingTreeModel doSetupKey(Iterator keyIterator, Iterator entriesIterator, FacesContext context, Object modelKey) {
           if (modelKey != null) {
           if (!setupModel(modelKey, context)) {
           //no key is available
           leaveModel(getRoot().stackEntries.iterator(), null, context);
           return null;
           }
           }
          
           if (keyIterator != null && keyIterator.hasNext()) {
           Key key = (Key) keyIterator.next();
           StackingTreeModel stackingTreeModel = this.getInternalModelById(key.modelId);
           Iterator nextEntriesIterator = null;
           Object nextModelKey = key.modelKey;
           ...
           ...
           ...
          }
          


          to

          protected StackingTreeModel doSetupKey(Iterator keyIterator, Iterator entriesIterator, FacesContext context, Object modelKey) {
           if (modelKey != null) {
           if (!setupModel(modelKey, context)) {
           //no key is available
           leaveModel(getRoot().stackEntries.iterator(), null, context);
           return null;
           }
           }
          
           if (keyIterator != null && keyIterator.hasNext()) {
          // Key key = (Key) keyIterator.next();
           Object o = keyIterator.next();
           if(o == null || !(o instanceof Key)) {
           leaveModel(entriesIterator, null, context);
           return null;
           }
          
           Key key = (Key) o;
           StackingTreeModel stackingTreeModel = this.getInternalModelById(key.modelId);
           Iterator nextEntriesIterator = null;
           Object nextModelKey = key.modelKey;
           ...
           ...
           ...
          }
          


          Is there any workaround to set back the selected node to null in case there is no root node?

          Thanks.

          • 3. Re: ClassCastException and IllegalStateException in tree man
            Yogesh Bhardwaj Newbie

            I have done an ugly hack to get around this issue for now, but if anyone knows of a better solution or a potential problem with this solution, please let me know

            FacesContext context = FacesContext.getCurrentInstance();
            UIComponentIterator uiComponentIterator = new UIComponentIterator(
             context.getViewRoot());
            
            while(uiComponentIterator.hasNext())
            {
             UIComponent component = (UIComponent) uiComponentIterator.next();
            
             if(component instanceof UITree)
             {
             UITree uiTree = (UITree) component;
             TreeState treeState = (TreeState) uiTree.getComponentState();
             treeState.setSelected(null);
             }
            }
            


            Thanks