5 Replies Latest reply on Jun 8, 2011 1:16 AM by Nikhil Patil

    Dynamic Tab deletion error

    Nikhil Patil Newbie

      I get the following error while trying to delete tab

       

      java.lang.NullPointerException
                at org.richfaces.component.AbstractTabPanel.getActiveItem(AbstractTabPanel.java:64)
                at org.richfaces.component.AbstractTogglePanel.encodeBegin(AbstractTogglePanel.java:168)
                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
                at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:278)
                at org.richfaces.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:58)
                at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
                at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
                at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
                at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853)
                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
                at org.richfaces.context.ExtendedPartialViewContextImpl$RenderVisitCallback.visit(ExtendedPartialViewContextImpl.java:514)
                at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:337)
                at javax.faces.component.UIComponent.visitTree(UIComponent.java:1485)
                at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
                at javax.faces.component.UIForm.visitTree(UIForm.java:335)
                at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
                at javax.faces.component.UIComponent.visitTree(UIComponent.java:1496)
                at org.richfaces.context.ExtendedPartialViewContextImpl.processPartialRenderPhase(ExtendedPartialViewContextImpl.java:284)
                at org.richfaces.context.ExtendedPartialViewContextImpl.processPartial(ExtendedPartialViewContextImpl.java:206)
                at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:974)
                at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652)
                at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:388)
                at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
                at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:159)
                at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
                at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:115)
                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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
                at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
                at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
                at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
                at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:107)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at com.googlecode.webutilities.filters.CompressionFilter.doFilter(CompressionFilter.java:94)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                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:235)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                at java.lang.Thread.run(Thread.java:619)
      
      

       

      <h:panelGroup layout="block" class="container clearfix" id="container">

                             <rich:tabPanel id="tabs" switchType="ajax" style="height:100%" itemChangeListener="#{us.changeTabName}" activeItem="#{us.currentTabId}">

                                       <c:forEach items="#{us.tabs}" var="tab" varStatus="it">

                                              <rich:tab

                                                                  name="#{tab.id}"

                                                                  id="#{tab.id}"

                                                                  data="#{tab}"

                                                                  oncomplete="#{tab.onComplete}">

                                                                  <f:facet name="header">

                                                                            <h:panelGroup>

                                                                                      <h:panelGroup style="width:105px; float:left;">

                                                                                                <h:outputText value="#{tab.header}" />

                                                                                      </h:panelGroup>

                                                                                      <h:panelGroup style="float: right;margin-top: -5px;">

                                                                                                <h:graphicImage library="images" name="btn_cancel.png"

                                                                                                                    rendered="#{tab.isClosable}"

                                                                                                                    style="cursor:pointer;border:0;"

                                                                                                              onclick="closeTab('#{tab.id}'); event.stopPropagation();"/>                               

                                                                                      </h:panelGroup>

                                                                            </h:panelGroup>

                                                                  </f:facet>

                                                                  <ui:include src="#{tab.includePath}" />

                                              </rich:tab>

                                    </c:forEach>

                          </rich:tabPanel>

      </h:panelGroup>

       

       

      and the delete tab function is

       

      <a4j:jsFunction data="#{us.currentTabId}" action="#{us.closeTab}" name="closeTab" render="container, tabs">

                                              <a4j:param name="currentTabId"/>

                          </a4j:jsFunction>

                 </h:form>

       

      What am I doing wrong?

        • 1. Dynamic Tab deletion error
          Ilya Shaikovsky Master

          do you assigning new tab to activeItem after current one deletion?

          • 2. Re: Dynamic Tab deletion error
            Nikhil Patil Newbie

            @Ilya

            Yes I am. Following is my code for closeTab method

             

            public void closeTab(){
            // getting tab id(i.e. name) to be deleted from request params
            String currentTabId = FacesContext
              .getCurrentInstance().getExternalContext()
              .getRequestParameterMap().get("currentTabId");
            
              // This is my POJO for tabs
              DashboardTab removedTab = null;
            
              for(DashboardTab tab: this.tabs){
              if(tab.getId().equals(currentTabId))
              {
              removedTab = tab;
              break;
              }
              }
            
              if (null != removedTab && removedTab.getIsClosable()){
              this.currentTabId="home"; // home is my first tab
              System.out.println("Removing tab : "+removedTab.getId() );
            
              // removing from list
              this.tabs.remove(removedTab) ;
              }
            }
            
            

            Two things which I observed were

            1. When I trigger commandLink to create first tab, the page is switched to the newly created tab. After this if I go back to my first tab and create another tab, the page is not automatically switched although the tab gets created.
            2. After getting the

            java.lang.NullPointerException

                      at org.richfaces.component.AbstractTabPanel.getActiveItem(AbstractTabPanel.java:64) error, if i refresh the page, I'm switched back to dashboard.

            What am I missing here?

            • 3. Re: Dynamic Tab deletion error
              Nikhil Patil Newbie

              @Ilya, it will be great if you could shed some light here! thanks.

              • 4. Re: Dynamic Tab deletion error
                Liffey Morgan Newbie

                I'm also getting this error - has any solution been found?

                • 5. Re: Dynamic Tab deletion error
                  Nikhil Patil Newbie

                  @Liffey, I switched to the client mode after all, and in client mode this problem does not occur. I opted for client mode for following reasons

                  1) I do not get the above error

                  2) From what I read around, people prefer client switch rather than a server or ajax switch, cause it makes the user experience better. The user can quickly navigate between tabs since the pages are preloaded.

                  3) I could afford pre-loading two tabs with client mode.

                   

                   

                  Its not a solution, but for me forunately the client mode was suitable so I could opt it.