primefaces tabView activeIndex问题 [英] primefaces tabView activeIndex issue
问题描述
我有两个类似的Tab的Primefaces TabView:
I have Primefaces TabView with two Tab like:
<p:tabView dynamic="true" cache="false"
onTabShow="scrollBottom(#{stanzaBean.activeIndex})"
tabChangeListener="#{messaggioBean.onTabChange}"
activeIndex="#{stanzaBean.activeIndex}" >
它工作正常,但当我更改选项卡时,activeIndex不会在服务器上更新,并且始终返回默认值. 我正在使用Primefaces 2.2.1.
it works fine, except that when I change the Tab the activeIndex isn't updated on the Server and it returns always the default value. I'm using primefaces 2.2.1.
谢谢.
推荐答案
PrimeFaces ShowCase示例,如果您为每个标签指定一个ID:
Going by the PrimeFaces ShowCase example, if you give each tab an id:
<p:tabView tabChangeListener="#{indexBean.onTabChange}" >
<p:tab title="tab 0" id="tab0"></p:tab>
<p:tab title="tab 1" id="tab1" ></p:tab>
<p:tab title="tab 2" id="tab2"></p:tab>
</p:tabView>
您可以在tabChangeListener中获得该标签ID.
you can get that tab id in the tabChangeListener.
public void onTabChange(TabChangeEvent event) {
System.out.println("tab id = " + event.getTab().getId());
}
然后,您将知道选择了哪个选项卡.
Then you'll know which tab was selected.
There is an open PrimeFaces issue 1640 TabView: Wrong activeIndex in TabChangeListener, always 0 on the problem you are having.
在PrimeFaces 5.0及更高版本中,tabChangeListener
在tabView
元素上不再可用,但应通过带有tabChange事件的显式ajax标记使用.
With PrimeFaces 5.0 and up the tabChangeListener
is no longer available on the tabView
element but should be used via an explicit ajax tag with a tabChange event.
<p:tabView id="analysisSections" value="#{analysisBean.analysis.sections}" var="section" activeIndex="#{analysisBean.activeIndex}">
<p:ajax event="tabChange" listener="#{analysisBean.onTabChange}"/>
您还可以直接获取标签的索引:
Also you can directly get index of tab:
public void onTabChange(TabChangeEvent event) {
activeIndex = ((TabView) event.getSource()).getIndex();
}
所有这些更改后,activeIndex正常工作.
with all these changes, activeIndex works properly.
这篇关于primefaces tabView activeIndex问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!