title: AJax Callback fails (NPE) on selectoneitem
body: <p>Used <a href="https://stackoverflow.com/questions/7687980">this StackOverflow answer</a> to try an implement a submitless form.  The page consists of a <code>selectomenu</code> control and a table.  On change of the selection I wish to refresh the table body.  The page loads without issues, but when the selection is made I get the following error occurs:</p>
  
  <pre><code>10:22:48,241 ERROR [[FacesServlet]] Servlet.service() for servlet FacesServlet threw exception: java.lang.NullPointerException
      at com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter(PartialViewContextImpl.java:441) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.context.PartialViewContextImpl.access$300(PartialViewContextImpl.java:71) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.context.PartialViewContextImpl$DelayedInitPartialResponseWriter.getWrapped(PartialViewContextImpl.java:582) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at javax.faces.context.PartialResponseWriter.startDocument(PartialResponseWriter.java:115) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
      at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:199) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505) [jbossweb-7.0.13.Final.jar:]
      at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445) [jbossweb-7.0.13.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
      at java.lang.Thread.run(Thread.java:636) [rt.jar:1.6.0_18]
  </code></pre>
  
  <p>I'm using JBoss-AS-7.1.1, and the <code>selectonmenu</code> looks like this:</p>
  
  <pre><code>&lt;h:selectOneMenu id="ship"
               value="#{shipManager.current}"&gt;
      &lt;f:selectItems value="#{shipManager.list}"
                 var="ship"
                 itemValue="#{ship}"
                 itemLabel="#{ship.name}" /&gt;
      &lt;f:ajax listener="#{shipManager.changeShip}" /&gt;
  &lt;/h:selectOneMenu&gt; 
  </code></pre>
  
  <p>If I remove the ajax component then no issues although (of course) the <code>shipManager</code> is not updated.</p>
  
  <p>Once I have the selection made I would then like to add the <code>renderer</code> part to refresh my table body.</p>
  
  <p>Many thanks for any help given.</p>
  
  <p>Steve</p>
  
  <p>As requested here is my XHTML code:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  
    &lt;h:head&gt;
      &lt;title&gt;Voyage Cruises&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;
      &lt;link type="text/css" rel="stylesheet" media="all" href="/css/screen.css"/&gt;
      &lt;link type="text/css" rel="stylesheet" media="all" href="/css/cruise.css"/&gt;
      &lt;script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"&gt;&lt;/script&gt; 
      &lt;script src="js/map.js" &gt;&lt;/script&gt;
      &lt;script src="js/cruise.js" &gt;&lt;/script&gt;
    &lt;/h:head&gt;
  
    &lt;h:body&gt;
      &lt;div id="page"&gt;
        &lt;div id="float-map"&gt;
      &lt;div id="map"&gt;&lt;/div&gt;
        &lt;/div&gt;
  
        &lt;h:form id="ship-form"&gt;
  
      &lt;div id="ship-controls"&gt;
        &lt;div class="float-ctrls"&gt;
          &lt;a href="/ports.html" title="Find Ports"&gt;&lt;img src="/images/action_search.png" alt="Find Ports"/&gt;&lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;span id="ship-selector" &gt;
            &lt;h:selectOneMenu id="ship"
                     value="#{shipManager.current}"&gt;
          &lt;f:selectItems value="#{shipManager.list}"
                     var="ship"
                     itemValue="#{ship}"
                     itemLabel="#{ship.name}" /&gt;
          &lt;f:ajax execute="ship" render="@form" listener="#{shipManager.changeShip}" /&gt;
            &lt;/h:selectOneMenu&gt; 
          &lt;/span&gt;
          &lt;select id="month" /&gt;
          &lt;select id="year" /&gt;
          &lt;br /&gt;
          &lt;span class="input-container"&gt;&lt;b&gt;Tonnage:&lt;/b&gt;&lt;input id="tonnage" type="text" size="6" value="30,277" /&gt;&lt;/span&gt;
          &lt;span class="input-container"&gt;&lt;b&gt;Audit Time:&lt;/b&gt;&lt;input id="audit" type="text" size="2" value="6" /&gt;&lt;/span&gt;
          &lt;span class="input-container"&gt;&lt;b&gt;Fleet:&lt;/b&gt;&lt;input id="fleet" type="text" size="20" value="P&amp;amp;O" /&gt;&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;table class="cruise"&gt;
        &lt;thead&gt;
          &lt;tr&gt;
            &lt;th class="date"&gt;Date&lt;/th&gt;
            &lt;th class="port"&gt;Port&lt;/th&gt;
            &lt;th class="arrive"&gt;Arrive&lt;/th&gt;
            &lt;th class="depart"&gt;Depart&lt;/th&gt;
          &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
          &lt;ui:repeat var="cruise"
                 value="#{cruiseManager.list}" 
                 varStatus="table"&gt;
            &lt;tr class="#{table.even ? 'even' : 'odd'}"&gt;
          &lt;td class="date"&gt;
            &lt;h:outputFormat value="{0, date,d MMM}"&gt;
              &lt;f:param value="#{cruise.date}" /&gt;
            &lt;/h:outputFormat&gt;
          &lt;/td&gt;
          &lt;h:panelGroup rendered="#{null != cruise.port}"&gt;
            &lt;td class="port"&gt;#{cruise.port.name}&lt;/td&gt;
            &lt;td class="arrive"&gt;
              &lt;h:outputFormat rendered="#{null != cruise.arrival}"
                      styleClass="#{cruise.arrivalEstimated ? 'est-time' : 'act-time'}"
                      value="{0, date,HH:mm}"&gt;
                &lt;f:param value="#{cruise.arrival}" /&gt;
              &lt;/h:outputFormat&gt;
            &lt;/td&gt;
            &lt;td class="depart"&gt;
              &lt;h:outputFormat rendered="#{null != cruise.departure}"
                      styleClass="#{cruise.departureEstimated ? 'est-time' : 'act-time'}"
                      value="{0, date,HH:mm}"&gt;
                &lt;f:param value="#{cruise.departure}" /&gt;
              &lt;/h:outputFormat&gt;
            &lt;/td&gt;
          &lt;/h:panelGroup&gt;
          &lt;h:panelGroup rendered="#{null == cruise.port}"&gt;
            &lt;td class="at-sea" colspan="3"&gt;At Sea&lt;/td&gt;
          &lt;/h:panelGroup&gt;
            &lt;/tr&gt;
          &lt;/ui:repeat&gt;
        &lt;/tbody&gt;
      &lt;/table&gt;
  
        &lt;/h:form&gt;
      &lt;/div&gt;
    &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And the ShipManager:</p>
  
  <pre><code>package com.nutrastat.voyager.web;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.ejb.EJB;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ViewScoped;
  import javax.faces.event.AjaxBehaviorEvent;
  
  import com.nutrastat.voyager.db.HarbourMasterLocal;
  import com.nutrastat.voyager.db.ShipEntity;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  @ManagedBean
  @ViewScoped
  public class ShipManager 
      implements Serializable {
  
      static final long serialVersionUID = -3017226836104715117L;
  
      private transient final Logger log;
  
      private ShipEntity currentShip;
  
      @EJB
      private HarbourMasterLocal harbourMaster;
  
      public ShipManager() {
      log = LoggerFactory.getLogger(getClass());
      }
  
      public ShipEntity getCurrent() {
      if (log.isInfoEnabled())
          log.info("getCurrent(): " + currentShip);
      return currentShip;
      }
  
      public void setCurrent(ShipEntity ship) {
      if (log.isInfoEnabled())
          log.info("setCurrent(" + currentShip + "): " + ship);
      currentShip = ship;
      }
  
      public void changeShip(AjaxBehaviorEvent evt) {
      if (log.isInfoEnabled())
          log.info("Ship now: " + currentShip);
      }
  
      public List&lt;ShipEntity&gt; getList() {
      try {
          return harbourMaster.listShips();
  
      } catch (Exception cause) {
          log.error("Getting the list of ships", cause);
          return new ArrayList&lt;ShipEntity&gt;(0);
      }
      }
  }
  </code></pre>