Reputation: 837
I've got a tab view that contains four tabs and three commandButtons(count,add to Table, export to Word) over them.
I input some text data in first tab, some numeric data in second tab, then when I am pressing first commandButton(count), my programm do some countings, but I can't set Active Index on third Tab where I show result of counting.
<h:form id="dataForm1" prependId="false">
<div>
<p:commandButton id="count" update="tbv" process="tbv:tab1 tbv:tab2" />
<p:commandButton id="addToWord" .... />
<p:commandButton id="exportToWord" ... />
</div
<div>
<p:growl id="growlm" showDetail="true" />
<p:tabView activeIndex="#{disableTag.activeTabIndex}" id="tbv" tabChangeListener="#{disableTag.onTabChange}">
<p:ajax event="tabChange" listener="#{disableTag.onTabChange}" update=":dataForm1:growlm" />
<p:tab id="tab1">some text data </p:tab>
<p:tab id="tab2">some numeric data</p:tab>
<p:tab id="tab3">result of counting from tab2</p:tab>
<p:tab id="tab4">table</p:tab>
</p:tabView>
Backing bean public int getActiveTabIndex() { return activeTabIndex; }
public void setActiveTabIndex(int activeTabIndex) {
this.activeTabIndex = activeTabIndex;
}
public void onTabChange(TabChangeEvent event) {
TabView tv = (TabView) event.getComponent();
this.setActiveTabIndex(tv.getActiveIndex());
System.out.println("###### ACtive tab: "+activeTabIndex);
}
But it is not working for me, do you have any idea: how i can set third tab activeIndex=2 after countings?
Upvotes: 1
Views: 7025
Reputation: 377
This is a way to get it:
// View
<h:form id="yourForm">
...
<p:commandButton value="Go to tab 3" action="#{yourBackingBean.doSomeCounting('2')}"
update="tabView"/>
...
</h:form>
then inside your counting method:
// BackingBean
public void doSomeCounting(String tabIndex){
// your counting logic
try {
activeTabIndex = Integer.parseInt(tabIndex);
System.out.println("showing tab: "+activeTabIndex);
} catch (NumberFormatException e) {}
}
If I understand correctly what you're intending.
Upvotes: 2