Search code examples
primefacescommandbuttontabview

How to change active tab after button click


I used PrimeFaces component tabView and i have code like below.

 <p:tabView id="tabs" dynamic="true" cache="false">
    <p:tab id="tab1">
         <ui:include src="/some/path/page.xhtml"/>
    </p:tab>
    <p:tab id="tab2">
         <ui:include src="/some/path/page2.xhtml"/>
    </p:tab>
    <p:tab id="tab3">
         <ui:include src="/some/path/page3.xhtml" />
    </p:tab>
</p:tabView>

On page3 i have ajax commandButton which looks like below.

<p:commandButton actionListener="#{bean.method(parameter)}" ajax="true" value="Add" />

I need switch to tab1 when method in bean finished. Thank you for help.


Solution

  • You have to add:

    activeIndex
    

    attribute to your tabView:

    <p:tabView id="tabs" dynamic="true" cache="false" activeIndex="1" >