title: Primefaces TabView throwing a null-pointer on third load of tab
body: <p>I have a tab view with three tabs. The tab view seems to work correctly in the first two tab changes, but on the third I get a null-pointer as in </p>
  
  <pre><code>java.lang.NullPointerException
  at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:59)
  </code></pre>
  
  <p>Also, TabChangeEvents have null data at this point. </p>
  
  <p>Making the contents of the tabs minimal (just a line of text), I can see that the contents of the tabs are being appended onto each other. Once this happens, the issues begin.</p>
  
  <p>Looking at the <a href="http://grepcode.com/file/repository.primefaces.org/org.primefaces/primefaces/5.0.RC2/org/primefaces/component/tabview/TabViewRenderer.java/" rel="nofollow">PrimeFaces source code</a>, it seems that it's when trying to work with the <code>tabToLoad</code> variable that is retrieved with the generated <code>tabClientId</code>. I'm not certain that it should be in the branch of logic that deals with new tabs either.</p>
  
  <p>My tab view looks as follows:</p>
  
  <pre><code>&lt;p:tabView styleClass="entities-tabview" id="tabs" dynamic="true"&gt;
      &lt;p:ajax event="tabChange" listener="#{action.onTabChange}"
              update="first-tab,second-tab"/&gt;
  
      &lt;p:tab title="First Tab" id="first-tab"&gt;
          tab one content
      &lt;/p:tab&gt;
  
      &lt;p:tab title="Second Tab" id="second-tab"&gt;
          tab two content
      &lt;/p:tab&gt;
  
      &lt;p:tab title="Other Tab" id="other-tab"&gt;
          // tab content
      &lt;/p:tab&gt;
  &lt;/p:tabView&gt;
  </code></pre>
  
  <p>It seems that the code checks if the <code>var</code> parameter is set on the TabView. As we do not use one, it is null, so it goes into the new tab branch. The tab index is set on the tabview though. Any ideas about what could be wrong?</p>
  
  <p>After some more investigation, I see that on a tab change the tab that should be changed to is specified via the request parameter with the client ID with <code>_newTab</code> appended to it. The first two times this is set correctly, but on changing back to the tab it is not set, hence not being able to find the tab and the subsequent NPEs.</p>
  
  <p><strong>Updated Cause</strong>
  With the tabs being dynamic, and the ajax event firing, the tabs are changed and subsequently the ajax updates the tabs. This seems to cause the issue where both tabs are loaded into the same tab, which most likely is messing up the parameters later on. </p>
  
  <p>But how to be able to do the tab change functions and have its details display in the tab?</p>