I have a primefaces tab view like this :
<p:tabView id="tabView">
<p:tab id="tab1" title="Godfather Part I">
This tab has static content.
</p:tab>
<p:tab id="tab2" title="Godfather Part II">
this tab has a datatable whose
</p:tab>
</p:tabView>
Now, what I want to do is, fire a managedbean method when user clicks on tab2. I can add an actionlistener on tabchange event of tabView but this will fire the method on click of tab1 too. How do I fire a method on click of tab2 only?
Action listener will be called at click of every tab of your tabView. But you can control your action Listener by conditional blocks like this. Here is an example:
<p:tabView id="tabView" dynamic="true">
<p:ajax event="tabChange" listener="#{Bean.onTabChange}" update=":messages" />
<p:tab id="tab1" title="#{userLbl['notification.headerIncoming']}">
<p:tab id="tab2" title="#{userLbl['notification.headerOutgoing']}">
</p:tabView>
Action Listener:
public void onTabChange(TabChangeEvent event) {
if (event.getTab().getId().equals("tab1")) {
//Your actions for tab1
} else if((event.getTab().getId().equals("tab2")) {
//Your actions for tab2
}
}
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