title: Primefaces tabview: set the active index on tab change
body: <p>I've got a tab view that contains two tab.</p>
  
  <p>When I switch from tab 1 to tab 2, I'm calling some code that executes a validation and updates some values. Depending on the result of this validation, I would like to stay on tab 1, or go to tab 2, and refresh the tabs' content.</p>
  
  <p>My tabview:</p>
  
  <pre><code>&lt;h:form id="form"&gt; 
      &lt;p:tabView id="tabview" activeIndex="#{ctrl.idx}" dynamic="true" cache="false"&gt;  
          &lt;p:ajax event="tabChange" listener="#{ctrl.doStuff}" update=":form:tabview"/&gt;
          &lt;p:tab title="Tab 1" id="t1"&gt;  
              &lt;h:panelGrid columns="1" cellpadding="10"&gt;
                  &lt;h:outputText value="#{ctrl.s1}"/&gt;
              &lt;/h:panelGrid&gt;  
          &lt;/p:tab&gt;  
          &lt;p:tab title="Tab 2" id="t2"&gt;  
              &lt;h:panelGrid columns="1" cellpadding="10"&gt;
                  &lt;h:outputText value="#{ctrl.s2}"/&gt;
              &lt;/h:panelGrid&gt;  
          &lt;/p:tab&gt;
      &lt;/p:tabView&gt;  
  &lt;/h:form&gt;
  </code></pre>
  
  <p>My test code that simly changes the values:</p>
  
  <pre><code>public void doStuff() {
      s1 = String.valueOf(Math.random());
      s2 = String.valueOf(Math.random());
  }
  </code></pre>
  
  <p>I thought that changing the active tab index in my method would be enough, like that:</p>
  
  <pre><code>public void doStuff() {
      // ...
      idx = 0;
  }
  </code></pre>
  
  <p>On tabChange event, the method is called but the tabview components goes to the clicked tab, ignoring the <code>idx</code> new value.</p>
  
  <p>I thought adding an update attribute to <code>p:ajax</code> would render the whole tabview but only the tabs and/or the tabs' content is re rendered.</p>
  
  <p>And weirdest of all, if I change <code>update=":form:tabview"</code> to <code>update=":form"</code> or <code>update="@form"</code>, I only receive the tab's content in the ajax response -> the component disappears from the page!</p>
  
  <p>My bean is viewscoped, I'm using Primefaces 3.5, JSF 2.1 and Tomcat 7.</p>
  
  <p>Any idea? Thanks.</p>