0 Replies Latest reply on Jan 26, 2013 9:40 AM by John Scott

    add dynamically tab to rich:tabPanel

    John Scott Newbie

      Dear Friends , i want add and remove tab dynamically , now i have managed to do this

       

        


       <rich:panelMenu >
           <rich:panelMenuGroup >
               <rich:panelMenuItem label="Users" name="Users"  action="#{tabsBean.createTabs('Users Tab')}" render="tabs" />
               <rich:panelMenuItem label="Orders" name="Orders"  action="#{tabsBean.createTabs('Orders Tab')}" render="tabs" />
           </rich:panelMenuGroup>                
       </rich:panelMenu>
      
          <h:panelGrid id="tabs" binding="#{tabsBean.panelGrid}"/>
      
      

      then i have a bean that manage the tabs

       

           

      package net.interneteidee.utility;
      
      import java.util.LinkedList;
      import java.util.List;
      
      import javax.annotation.PostConstruct;
      import javax.faces.application.Application;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.SessionScoped;
      import javax.faces.component.UIData;
      
      import javax.faces.component.html.HtmlPanelGrid;
      import javax.faces.context.FacesContext;
      import org.richfaces.component.SwitchType;
      import org.richfaces.component.UITab;
      import org.richfaces.component.UITabPanel;
      
      
      
      @ManagedBean
      @SessionScoped
      public class TabsBean {
      
          private HtmlPanelGrid panelGrid;
          private UITabPanel tabPanel;
          private List<UITab> tabsList;
          private Application application;
      
          public TabsBean() {
      
              tabsList = new LinkedList<UITab>();
              
          }
      
          @PostConstruct
          public void init(){
      
              FacesContext context = FacesContext.getCurrentInstance();
              application = context.getApplication();
              tabPanel = (UITabPanel)application.createComponent(UITabPanel.COMPONENT_TYPE);
              tabPanel.setSwitchType(SwitchType.ajax);
          
      
          }
      
          public void createTabs (String name){        
      
      
              UITab tab = new UITab();
              tab = (UITab)application.createComponent(UITab.COMPONENT_TYPE);
              tab.setName(name);
              tabPanel.getChildren().add(tab);
              UIData d = new UIData();
          
              
              panelGrid.getChildren().add(tabPanel);
          
          
          }
      
          public UITabPanel getTabPanel() {
              return tabPanel;
          }
      
          public void setTabPanel(UITabPanel tabPanel) {
              this.tabPanel = tabPanel;
          }
      
          public List<UITab> getTabsList() {
              return tabsList;
          }
      
          public void setTabsList(List<UITab> tabsList) {
              this.tabsList = tabsList;
          }
      
          public Application getApplication() {
              return application;
          }
      
          public void setApplication(Application application) {
              this.application = application;
          }
      
          public HtmlPanelGrid getPanelGrid() {
              return panelGrid;
          }
      
          public void setPanelGrid(HtmlPanelGrid panelGrid) {
              this.panelGrid = panelGrid;
          }
      
      
      }
      

         

            

         

       

       

      now my problem is that i must add of components a this tabs (datatable that contains all user , form for insert a user and other)

       

       

      how can i do?