0 Replies Latest reply on Aug 26, 2013 1:40 PM by Ankit Mahajan

    JSF tree & modal panel class cast exception

    Ankit Mahajan Newbie

      Hi All

       

      I am using JSF1.2 and Richfaces 3.3.

      I have two two textboxes and two editlinks corresponding to each ex: TXT1:editlnk1       TXT2:editlink2

      Editlink1 opens a modal panel which has Tree structure defined in it,upon selecting a leaf node and clicking save button, value is saved in TXT1.

      Editlink2 opens separate modal panel which has Picklist showing left & right values,upon selection selected values are sved in TXT2.

       

      Everything works fine, except in following scenario:

      1. Click editlink1 and select a leaf node and close that modal panel.(It doesn't matter if I click save or not.)

      2. Now Click editlink2 associated to pick list, I am getting following exception: also attached it.

       

      HTTP Status 500 - java.lang.String cannot be cast to org.richfaces.model.StackingTreeModelKey


      type Exception report

      message java.lang.String cannot be cast to org.richfaces.model.StackingTreeModelKey

      description The server encountered an internal error that prevented it from fulfilling this request.

      exception

      javax.servlet.ServletException: java.lang.String cannot be cast to org.richfaces.model.StackingTreeModelKey javax.faces.webapp.FacesServlet.service(FacesServlet.java:277) org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206) org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515) 

      root cause

      java.lang.ClassCastException: java.lang.String cannot be cast to org.richfaces.model.StackingTreeModelKey org.richfaces.model.StackingTreeModel.doSetupKey(StackingTreeModel.java:153) org.richfaces.model.StackingTreeModel.setupKey(StackingTreeModel.java:191) org.richfaces.model.StackingTreeModel.setRowKey(StackingTreeModel.java:497) org.richfaces.model.StackingTreeModel.setRowKey(StackingTreeModel.java:493) org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:351) org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:324) org.richfaces.renderkit.TreeRendererBase.getSelectionValue(TreeRendererBase.java:528) org.richfaces.renderkit.TreeRendererBase.encodeSelectionStateInput(TreeRendererBase.java:553) org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:236) org.richfaces.renderkit.html.TreeRenderer.doEncodeEnd(TreeRenderer.java:253) org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134) javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:244) com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:241) com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180) com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277) org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258) org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:78) javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83) org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157) org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:124) org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:685) org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:556) javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:266) com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:197) org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100) org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206) org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515) 

       

       

      I am creating those editlinks dynamically from Java code.Please find code segment:

       

        HtmlInputText inputTxt = new HtmlInputText();

                                  inputTxt.setId("textbox" + metadataCounter);

                                  //inputTxt.setReadonly(true);

                                  inputTxt.setValueExpression("value", createValueExpression("#{dataItem.attributeList[" + metadataCounter + "].attributeCurrValue}", String.class));

                                 

                                  HtmlAjaxCommandButton outLink=new HtmlAjaxCommandButton();

                                 

                                  outLink.setAjaxSingle(true);

                                  outLink.setId("editlink" + metadataCounter);

                                  outLink.setValue("..");

                                  outLink.setOncomplete("document.getElementById('editCascadePanelMultilist').component.show()");

                                 

                                 ValueExpression  v = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{dataItem.attributeList[" + metadataCounter + "]}", AttributeBean.class);

                                 ValueExpression  t = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{ManageBean.currentAttribute}", AttributeBean.class);

       

                                 ActionListener handler = new SetPropertyActionListenerImpl(t, v);

       

                                 outLink.addActionListener(handler);

      idColumn.getChildren().add(inputTxt);

                                 idColumn.getChildren().add(outLink);

       

      Both Modal panel Codes:

       

        <%-- Panel to display PickList for Multilits Simple Lists --%>

                   <rich:modalPanel id="editPanel" autosized="true" width="450" >

                      <f:facet name="header">

                          <h:outputText value="Multi Selection" />

                      </f:facet>

                      <f:facet name="controls">

                          <h:panelGroup>

                              <h:graphicImage value="/images/close.png" id="hidelink"

                                  styleClass="hidelink" title="Close"/>

                              <rich:componentControl for="editPanel" attachTo="hidelink"

                                         operation="hide" event="onclick" />

                          </h:panelGroup>

                      </f:facet>

                      <h:form id="displaymulitilistsimplelist">

                          <rich:messages style="color:red;"></rich:messages>

                          <h:panelGrid columns="1">

                              <a4j:outputPanel id="out1" ajaxRendered="true">

                                  <h:panelGrid id="pg1" columns="2">

                                      <h:outputText value="#{ManageBean.currentAttribute.attributeName}" /><br>

                                      <h:outputText value="Multi Select" /><br>

                                      <rich:pickList id="picklist" value="#{ManageBean.currentAttribute.listValues}" >

       

                                          <f:selectItems value="#{ManageBean.currentAttribute.listSelectValues}"/>

                                      </rich:pickList>

                                  </h:panelGrid>

                              </a4j:outputPanel>

       

                          </h:panelGrid>

                                             

                       

      <div align="center">

      <a4j:commandButton id="saveMultiList" value="OK" action="#{ManageBean.saveMultiListDetails}"

                                                 reRender="dataTableForm:RedlineTable"

                                                 oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();"  /></div>

                      </h:form>

       

                  </rich:modalPanel>

                 

                 <%-- Panel to display tree structure for Single List Cascade Lists  --%>

                 <rich:modalPanel id="editCascadePanel" autosized="true" width="450">

                     

                      <f:facet name="header">

                          <h:outputText value="Single Selection" />

                      </f:facet>

                      <f:facet name="controls">

                          <h:panelGroup>

                              <h:commandButton image="/images/close.png" id="hidelink2" action="#{ManageBean.closeWithoutSaving}"

                                  styleClass="hidelink" title="Close"/>

                              <rich:componentControl for="editCascadePanel" attachTo="hidelink2"

                                         operation="hide" event="onclick" />

                          </h:panelGroup>

                      </f:facet>

                     <h:form id="displaysimplelistcascadelist">

                          <rich:messages style="color:red;"></rich:messages>

                         <h:commandButton image="/images/close.png" id="hidelink2" action="#{ManageBean.closeWithoutSaving}"

                                  styleClass="hidelink" title="Close"/>

                          <h:panelGrid columns="1">

                             <a4j:outputPanel id="out2" ajaxRendered="true">

                                  <h:panelGrid id="pg2" columns="3" width="100%" columnClasses="col1,col2,col3">

       

                                     

                                      <rich:tree style="width:300px" toggleOnClick="true"

                                      nodeSelectListener="#{ManageBean.processSelection}"

                                      reRender="selectedNode" switchType="client"

                                      ajaxSubmitSelection="true" value="#{ManageBean.currentAttribute.cascadeListValues}"

                                      var="item" >

                                      </rich:tree>

                     

                                      <h:outputText escape="false"

                                                value="Selected Value:" id="selectedNode2" />

                                      <h:inputText value="#{ManageBean.currentAttribute.listValues[0]}" id="selectedNode" readonly="true" />

                    

                                  </h:panelGrid>

                              </a4j:outputPanel>

                          </h:panelGrid>

      <div align="center">

      <a4j:commandButton value="OK" action="#{ManageBean.saveMultiListDetails}"

                                                 reRender="dataTableForm:RedlineTable"

                                                 oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editCascadePanel')}.hide();" /></div>

                      </h:form>

       

                  </rich:modalPanel>

                 

                   

      Process Selection code I am using to find child nodes:

      public void processSelection(NodeSelectedEvent event) {

                           

                              System.out.println("Inside Process selection------------");

                              HtmlTree tree = (HtmlTree) event.getComponent();

                            

                           

                           //   selectedNodeChildren.clear();

                              List<String> current=currentAttribute.getSelectedNode();

                              current.clear();

                              currentAttribute.setSelectedNode(current);

       

                              TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());

                              if (currentNode.isLeaf()) {

                                 

                                  ListRowKey<String> rowKey=(ListRowKey<String>)tree.getRowKey();

                                  String rowKeyRemoveColon=rowKey.getPath().replaceAll(":", "");

                                  //nodeTitle = (String) tree.getRowData();

                                  //currentAttribute.setListValues(new String[]{(String) tree.getRowData()});

                                  currentAttribute.setListValues(new String[]{rowKeyRemoveColon});

                                  current.add((String) currentNode.getData());

                                  currentAttribute.setSelectedNode(current);

                                  //selectedNodeChildren.add((String) currentNode.getData());

                                 

                              } else {

                                        Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();

                                        while (it != null && it.hasNext()) {

                                                  Map.Entry<Object, TreeNode> entry = it.next();

                                                 

                                                  current.add(entry.getValue().getData().toString());

                                                  currentAttribute.setSelectedNode(current);

                                                  //currentAttribute.getSelectedNode().add(entry.getValue().getData().toString() );;

                                         //         selectedNodeChildren.add(entry.getValue().getData().toString() );

                                        }

                              }

                    }

       

                              

      As you can see my Tree has String as key but i am not able to understand why I am getting this error only when I click modal panel for picklist after selecting leaf node.

      I am not able to find root cause of the issue from last 3 days. Please help.

      Please let me know if you need any more info.Any help will be greatly appreciated.

       

      Thanks

      Ankit