I have a tab containing two tabs.
When I switch from tab 1 to tab 2, I invoke code that performs validation and updates some values. Depending on the result of this check, I would like to stay on tab 1 or go to tab 2 and update the contents of the tabs.
My tab:
<h:form id="form"> <p:tabView id="tabview" activeIndex="#{ctrl.idx}" dynamic="true" cache="false"> <p:ajax event="tabChange" listener="#{ctrl.doStuff}" update=":form:tabview"/> <p:tab title="Tab 1" id="t1"> <h:panelGrid columns="1" cellpadding="10"> <h:outputText value="#{ctrl.s1}"/> </h:panelGrid> </p:tab> <p:tab title="Tab 2" id="t2"> <h:panelGrid columns="1" cellpadding="10"> <h:outputText value="#{ctrl.s2}"/> </h:panelGrid> </p:tab> </p:tabView> </h:form>
My test code that just changes the values:
public void doStuff() { s1 = String.valueOf(Math.random()); s2 = String.valueOf(Math.random()); }
I thought that changing the active tab index in my method would be enough, for example:
public void doStuff() {
The method is called in the tabChange event, but the tabview components go to the clicked tab, ignoring the new idx value.
I thought that adding the update attribute to p:ajax would display the entire tab, but only the tabs and / or the contents of the tabs would be displayed.
And the strangest thing is, if I change update=":form:tabview" to update=":form" or update="@form" , I get only the contents of the tab in the ajax response → the component disappears from the page!
My bean is being browsed, I am using Primefaces 3.5, JSF 2.1 and Tomcat 7.
Any idea? Thanks.
source share