2 Replies Latest reply on Dec 21, 2011 5:09 PM by kwutzke

    Tab panel still throwing NPE on activeItem - FIX?

    kwutzke

      I have the following simple view main.xhtml, the request URL would be something like:

       

      http://localhost:8080/myproj/main.jsf?pq=2

       

      {code}<ui:composition xmlns="http://www.w3.org/1999/xhtml"

                      xmlns:c="http://java.sun.com/jsp/jstl/core"

                      xmlns:f="http://java.sun.com/jsf/core"

                      xmlns:h="http://java.sun.com/jsf/html"

                      xmlns:ui="http://java.sun.com/jsf/facelets"

                      xmlns:a4j="http://richfaces.org/a4j"

                      xmlns:rich="http://richfaces.org/rich"

                      template="/templating/layout-2col.xhtml">

       

        <ui:define name="metadata">

          <f:metadata>

            <f:viewParam name="pq" value="#{pqHome.id}" required="true">

              <f:convertNumber integerOnly="#{true}" />

            </f:viewParam>

            <f:event type="preRenderView" listener="#{pqHome.init}" />

          </f:metadata>

        </ui:define>

       

        ...

       

        <ui:define name="content-right">

          <h:form>

            <rich:panel>

              <f:facet name="header">

                Menu

              </f:facet>

              <rich:tabPanel binding="#{pqHome.tabPanel}">

              </rich:tabPanel>

            </rich:panel>

          </h:form>

        </ui:define>

       

      </ui:composition>{code}

      My bean:

       

      {code}@ManagedBean

      @RequestScoped

      public class PqHome implements Serializable

      {

          @Inject

          private PqService pqService;

         

          //@ManagedProperty(value="#{param.pq}")

          private Integer id;

          private Prequalification instance;

         

          @Inject

          private PqPartnerListQuery pplq;

          private List<Partner> partners;

         

          private UITabPanel tabPanel;

          private List<UIComponent> tabs;

         

          private String defaultTabName;

         

          //@PostConstruct

          public void init()

          {

              //id = 2;

             

              System.out.println("ID is " + id);

             

              instance = pqService.findSingleInstance(id);

             

              partners = pplq.getItemsForPq(id);

             

              System.out.println("Building tab panel programmatically...");

             

              // RF way...

              FacesContext fc = FacesContext.getCurrentInstance();

              Application application = FacesContext.getCurrentInstance().getApplication();

             

              tabPanel = (UITabPanel)application.createComponent(UITabPanel.COMPONENT_TYPE);

              tabPanel.setSwitchType(SwitchType.client);

             

              tabs = tabPanel.getChildren();

             

              for ( Partner partner : partners )

              {

                  Company co = partner.getCompany();

                  String companyName = co.getName();

                 

                  UITab tab = (UITab)application.createComponent(UITab.COMPONENT_TYPE);

                 

                  tab.setTitle(companyName);

                  tab.setName(companyName);

                  //tab.setId(companyName); // causes error on validateId

                  tab.setId(co.getDndType());

                 

                  tabs.add(tab);

              }

       

              System.out.println("Added " + tabs.size() + " tabs...");

       

              boolean activateLast = true;

             

              int defaultIndex = activateLast ? partners.size() - 1 : 0;

              defaultTabName = partners.get(defaultIndex).getCompany().getName();

             

              System.out.println("Default tab name = " + defaultTabName);

             

              System.out.println("getActiveItem() returns: " + tabPanel.getActiveItem());

             

              tabPanel.setActiveItem(defaultTabName);

          }

       

          public Integer getId()

          {

              return id;

          }

       

          public void setId(Integer id)

          {

              this.id = id;

          }

       

          public Prequalification getInstance()

          {

              return instance;

          }

       

          public List<Partner> getPartners()

          {

              return partners;

          }

         

          public Integer getNumPartners()

          {

              return partners.size();

          }

         

          public UITabPanel getTabPanel()

          {

              return tabPanel;

          }

       

          public void setTabPanel(UITabPanel tabPanel)

          {

              this.tabPanel = tabPanel;

          }

       

          public String getDefaultTabName()

          {

              return defaultTabName;

          }   

      }{code}

       

      When requesting the above page I get an NPE saying:

       

      {code}Caused by: java.lang.NullPointerException

          at org.richfaces.component.AbstractTabPanel.getActiveItem(AbstractTabPanel.java:55) [richfaces-components-ui-4.1.0-SNAPSHOT.jar:]

          at org.richfaces.component.AbstractTogglePanel.encodeBegin(AbstractTogglePanel.java:161) [richfaces-components-ui-4.1.0-SNAPSHOT.jar:]

          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276) [richfaces-components-ui-4.1.0-SNAPSHOT.jar:]

          at org.richfaces.renderkit.html.PanelRenderer.encodeEnd(PanelRenderer.java:181) [richfaces-components-ui-4.1.0-SNAPSHOT.jar:]

          at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:883) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1659) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:853) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1652) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1655) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]

          at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]

          at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273) [jboss-jsf-api_2.0_spec-1.0.0.Final.jar:1.0.0.Final]

          at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]

          at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.0.4-b09-jbossorg-4.jar:2.0.4-b09-jbossorg-4]

          ... 19 more{code}

      Even when explicitly using a activeItem as set by the bean, the same exception occurrs.

       

      <rich:tabPanel binding="#{pqHome.tabPanel}" activeItem="#{pqHome.defaultTabName}">

       

      The bug seems to be this:

       

      https://issues.jboss.org/browse/RF-10961

       

      Other issues with tab panels and switching are:

       

      https://issues.jboss.org/browse/RF-10945

      https://issues.jboss.org/browse/RF-11054

      https://issues.jboss.org/browse/RF-11081

       

      The only workaround to the NPE in RF-10961 I came up with would be to uncomment the `@ManagedProperty` and `@PostConstruct` annotations in the bean and outcomment the `<f:event ...>` in the view, but then I don't see why I should be using JSF 2 `<f:viewParam>` and `<f:metadata>` at all.

       

      When will bug RF-10961 finally be fixed? I'm using RF 4.1.0.SNAPSHOT from 2011-10-09. Shouldn't the current snapshot include the fix for this bug which is said to be "4.1.0.Milestone3"? Is the current bug fix one another branch?

       

      Thanks

      Karsten