如何在使用Ajax单击命令按钮时动态地在tabview
中添加标签primefaces
?
<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
。请帮助。谢谢。
在方法中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");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句