How do I switch to a tab (<p:tab>
) using a command button?
There is also a client side api method called selectTab(index);
<p:commandButton type="button" onclick="widgetvar.selectTab(2)" value="Show" />
p:tabView
has an attribute activeIndex
that is the "Index of the active tab" (Primefaces Documentation).
You could set this attribute from the action method of your p:commandButton
:
<p:commandButton value="Switch tab" action=#{myBean.switchTab} />
Define an action method switchTab() in your backing bean and let it set a member activeTab
.
Then use this member to set your active tab
<p:tabView activeIndex=#{myBean.activeTab}>
If your server supports EL 2.2 you can set the index of the active tab with the action method call:
<p:commandButton value="Switch tab" action=#{myBean.switchTab(2)} />
Then you can use the argument of your action method call to set the active index directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With