【问题标题】:How to add tabs in tabview in primefaces, dynamically, on click of a command button?如何在单击命令按钮时动态地在 Primefaces 的 tabview 中添加选项卡?
【发布时间】:2014-03-10 06:46:24
【问题描述】:

如何在使用 ajax 单击命令按钮时动态地在 primefaces 中的 tabview 中添加选项卡?

     <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>

支持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;
    }

这是我的支持 bean。我是jsf 和Primefaces 的新手。请帮忙。 谢谢。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    在addTab()方法中,可以添加,

    TabView tabView = new TabView();
    Tab newTab = new Tab();            
    newTab.setTitle("Tab Title");       
    tabView.getChildren().add(newTab); 
    

    您应该更新视图以反映新选项卡。使用RequestContext 进行ajax 更新。

    RequestContext context = RequestContext.getCurrentInstance();  
      context.update("tabview");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-30
      • 2011-09-24
      • 2013-08-18
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多