title: How to dynamically add and remove a tab in p:tabView component
body: <p>I am trying to add a PrimeFaces <code>&lt;p:tab&gt;</code> dynamically. While adding the second tab I am getting the following exception:</p>
  
  <blockquote>
    <p>"java.lang.IllegalStateException: Component ID tab0 has already been found in the view".</p>
  </blockquote>
  
  <p>How can I solve this?</p>
  
  <p>Here is the view code:</p>
  
  <pre><code>&lt;h:form prependId="false"&gt;
      &lt;p:tabView id="tabview" dynamic="true" cache="false" 
          binding="#{testBean.tabView}" 
          activeIndex="#{testBean.activeTab}" &gt;  
          &lt;h:commandButton value="Close" action="#{testBean.removeTab}"/&gt;
      &lt;/p:tabView&gt;  
      &lt;h:commandButton value="Add Tab" action="#{testBean.addTab}"/&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Here is the bean code:</p>
  
  <pre><code>public String addTab() {
      String tabId="tab"+id;
      System.out.println("Gen Id: "+tabId);
      tab = new Tab();
      tab.setTitle("Title: "+tabId);
      tab.setId(tabId);
  
      System.out.println("Tab Id: "+tab.getId());
      tabView.getChildren().add(id,this.tab);
      id++;
      return "tabtest.jsf";
  }
  
  public String removeTab() {
      tabView.getChildren().remove(activeTab);
      return "tabtest.jsf";
  }
  </code></pre>