title: Apache Tomcat + JSF + Primefaces: Ajax update cause fail on form
body: <p>My environment is:<br>
  PrimeFaces: 3.1.1<br>
  Server: Apache Tomcat 7.0.34.0<br>
  JSF: Mojarra 2.2.0<br>
  JDK: 1.7.0_25<br>
  IDE: Netbeans 7.3.1<br>
  SO: Linux Ubuntu 13.04 64bits<br></p>
  
  <p>I am having the following situation: <br>
  There is in my xhtml a form with several components. One of this components is this below:</p>
  
  <pre><code>        &lt;h:panelGrid columns="4" rendered="#{!inputControlador.tipoDocumentoPessoa()}"&gt;
              &lt;p:autoComplete value="#{inputControlador.movimentacao.fornecedor}"
                              completeMethod="#{inputControlador.completaPjs}"
                              id="fornecedor"
                              rendered="#{!inputControlador.tipoDocumentoPessoa()}"
                              size="50"
                              var="pj"
                              itemLabel="#{pj}"
                              itemValue="#{pj.id}"
                              forceSelection="true"
                              converter="#{inputControlador.converterPJ}"                                                     
                              onkeydown="cleanCampos(this.id)"&gt;                                                    
                  &lt;p:ajax event="itemSelect" 
                          listener="#{inputControlador.primeiraCategoria}" 
                          update="@form"/&gt;
              &lt;/p:autoComplete&gt;
          ...
          &lt;/h:panelGrid&gt;
  </code></pre>
  
  <p>When I choose a element in the autoComplete component the anothers autoCompletes in the form start to fail with this error:</p>
  
  <pre><code>        Set 11, 2013 7:00:38 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
          SEVERE: Error Rendering View[/privado/input/input/edita.xhtml]
          java.lang.NullPointerException
                  at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeSuggestionsAsList(AutoCompleteRenderer.java:366)
                  at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeSuggestions(AutoCompleteRenderer.java:313)
                  at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeResults(AutoCompleteRenderer.java:92)
                  at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeEnd(AutoCompleteRenderer.java:74)
                  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
                  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
                  at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
                  at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at javax.faces.component.UIForm.visitTree(UIForm.java:371)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
                  at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
                  at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319)
                  at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219)
                  at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
                  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
                  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:417)
                  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
                  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
                  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
                  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at br.com.clicksistemas.web.FiltroEntityManager.doFilter(FiltroEntityManager.java:73)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
                  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
                  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
                  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
                  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                  at java.lang.Thread.run(Thread.java:724)
  
          java.lang.IllegalStateException: CDATA tags may not nest
                  at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:681)
                  at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:179)
                  at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:341)
                  at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:210)
                  at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
                  at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:124)
                  at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
                  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
                  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at br.com.clicksistemas.web.FiltroEntityManager.doFilter(FiltroEntityManager.java:73)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
                  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
                  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
                  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
                  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                  at java.lang.Thread.run(Thread.java:724)
          java.lang.IllegalStateException: getWriter() has already been called for this response
                  at org.apache.catalina.connector.Response.getOutputStream(Response.java:605)
                  at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:197)
                  at br.com.clicksistemas.web.FiltroEntityManager.sendProcessingError(FiltroEntityManager.java:172)
                  at br.com.clicksistemas.web.FiltroEntityManager.doFilter(FiltroEntityManager.java:113)
                  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
                  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
                  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
                  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
                  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
                  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
                  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
                  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
                  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                  at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>The interesting (or not) about this is that the same code runs fine deploying at Windows in mostly cases, occuring rarely.</p>
  
  <p>If instead of send a update for entirely form sent only for some components someones of its don't stay consitently. Don't show or hide, the values stay wrong.</p>
  
  <p>It is a very weird behaviour and only occurs on this page, on this component.</p>