单击命令按钮后,如何动态地在选项卡视图中的选项卡视图中添加选项卡? [英] How to add tabs in tabview in primefaces, dynamically, on click of a command button?
本文介绍了单击命令按钮后,如何动态地在选项卡视图中的选项卡视图中添加选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在使用ajax单击命令按钮时动态地在primefaces
的tabview
中的选项卡中添加标签?
How do I add tabs in tabview
in primefaces
, dynamically, on click of a 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>
后备豆是
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;
}
这是我的后援豆.我是jsf
和Primefaces
的新手.请帮助.
谢谢.
This is my backing bean. I am new to jsf
and Primefaces
. Kindly help.
Thank you.
推荐答案
在方法addTab()
中,您可以添加
TabView tabView = new TabView();
Tab newTab = new Tab();
newTab.setTitle("Tab Title");
tabView.getChildren().add(newTab);
并且您应该更新视图以反映新选项卡.使用RequestContext
进行Ajax更新.
And you should update the view to reflect the new tab. Use RequestContext
for ajax update.
RequestContext context = RequestContext.getCurrentInstance();
context.update("tabview");
这篇关于单击命令按钮后,如何动态地在选项卡视图中的选项卡视图中添加选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文