Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch p:tab in the same form using a command button

How do I switch to a tab (<p:tab>) using a command button?

like image 311
Bryn Avatar asked Apr 18 '11 08:04

Bryn


2 Answers

There is also a client side api method called selectTab(index);

<p:commandButton type="button" onclick="widgetvar.selectTab(2)" value="Show" />
like image 72
Cagatay Civici Avatar answered Nov 20 '22 12:11

Cagatay Civici


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.

like image 35
Matt Handy Avatar answered Nov 20 '22 11:11

Matt Handy