1 Reply Latest reply on Jun 7, 2011 4:07 AM by Ján Jamrich

    Removal of Tab's causing Null Pointer Exception

    Liffey Morgan Newbie

      I'm trying to dynamically remove tabs within a TabPanel, using a function that calls a removal method on the main bean.  When I do this however, I keep getting the following NPE:

       

      java.lang.NullPointerException

                          at org.richfaces.component.AbstractTabPanel.getActiveItem(AbstractTabPanel.java:64)

       

      Here's the relevant code snippets ...

       

      testdelete.xhtml

      <h:form>

      <a4j:outputPanel id="mainTabPanel">

      <rich:tabPanel id="mainTab" activeItem="TAB1" switchType="server">

      <c:forEach items="#{TabBean.listOfTabs}" var="tab">

      <rich:tab id="#{tab.tabId}">

      <f:facet name="header">

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

      <h:commandLink value="Close" rendered="#{tab.isClosable}" onclick="removeTab('#{tab.tabId}');"/>

      </f:facet>

      <h:outputText value="text text text"/>

      </rich:tab>

      </c:forEach>

      </rich:tabPanel>

      </a4j:outputPanel>

       

      <a4j:jsFunction name="removeTab"

                          action="#{TabBean.removeTab}" 

                           render="mainTabPanel"

                           oncomplete="#{rich:component('mainTab')}.switchToItem('TAB1');">

      <a4j:param name="removeTabId"/>

      </a4j:jsFunction>

      </h:form>

       

       

      TabBean.java

      - this has the obvious getters/setters used, and the following methods for removing a tab ...

       

      public Tab getTabById (String tabId)

      {

      for (Tab currentTab: listOfTabs )

      {

      if ( currentTab.getTabId().equals(tabId))

      {

      return currentTab;

      }

      }

      return null;

      }

       

      public void removeTab () throws Exception

      {

      setActiveTabId("TAB1");

       

      String tabIdToRemove = FacesContext.getCurrentInstance().getExternalContext()                                                                                                                             .getRequestParameterMap().get("removeTabId");

      Tab currentTab = getTabById(tabIdToRemove);

       

      if ( currentTab != null )

      {

      listOfTabs.remove(currentTab);

      }

      else

      {

      throw new Exception("Tab Id parameter is null");

      }

      }