jsf - How to add tabs in tabview in primefaces, dynamically, on click of a command button? -


how add tabs in tabview in primefaces, dynamically, on click of command button using ajax?

     <p:tabview id="tabview" dynamic="true" cache="false"      binding="#{testbean.tabview}"      activeindex="0"      scrollable="true">          <p:tab title="tab1" closable="true">             <h:outputlabel value="1"></h:outputlabel>         </p:tab>         <p:tab title="tab2" closable="true">             <h:outputlabel value="2"></h:outputlabel>         </p:tab>         <p:tab title="tab3" closable="true">             <h:outputlabel value="3"></h:outputlabel>         </p:tab>     </p:tabview> 

backing bean

public class testbean {      tabview tabview;     int id=0;        public testbean() {     }      public string addtab() {          string tabid="tab"+id;         tab tab = new tab();         tab.settitle("title: "+tabid);        tab.setid(tabid);          tabview.getchildren().add(id,tab);          id++;         return "tabtest.jsf";     }      public tabview gettabview() {         return tabview;     }       public void settabview(tabview tabview) {         this.tabview = tabview;     } 

this backing bean. new jsf , primefaces. kindly help. thank you.

in method addtab() , can add,

tabview tabview = new tabview(); tab newtab = new tab();             newtab.settitle("tab title");        tabview.getchildren().add(newtab);  

and should update view reflect new tab. use requestcontext ajax update.

requestcontext context = requestcontext.getcurrentinstance();     context.update("tabview"); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -