Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke JavaScript when specific tab is clicked

Tags:

jsf

primefaces

i am exploring the tab components in primefaces http://www.primefaces.org/showcase/ui/tabviewChangeListener.jsf , and i was wondering if it's possible to invoke a JavaScript when a specific tab is being clicked.

please advise, thanks.

like image 577
Mahmoud Saleh Avatar asked Feb 16 '26 19:02

Mahmoud Saleh


1 Answers

There are two ways to hook up on tab change events:

  1. Use onTabChange attribute of <p:tabView> tag to execute a callback function on the appropriate event:

    <p:tabView onTabChange="handleTabChange(index)">
    //tabs
    </p:tabView>
    
  2. Use oncomplete attribute of <p:ajax> tag to execute a JS function when AJAX call completes successfully:

            <p:ajax event="tabChange" listener="#{tabBean.onTabChange}" oncomplete="handleOncomplete(xhr, status, args)"/>
    
like image 62
skuntsel Avatar answered Feb 19 '26 10:02

skuntsel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!