O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using TabView with dynamic tabs and event listeners support

Let us look at how we can create a TabView component with dynamic number of tabs that are loaded lazily and handle tabChange and tabClose events:

  1. Create a TabView component backed by server-side data and register tabChange and tabClose event listeners:
    <p:tabView value="#{tagController.tags}" var="tag" dynamic="true" cache="false" activeIndex="2">
      <p:ajax event="tabChange" listener="#{sampleController.onTabChange}"/> 
      <p:ajax event="tabClose" listener="#{sampleController.onTabClose}"/>
      
      <p:tab title="#{tag.label}" closable="true" disabled="#{empty tag.posts}">
        <h:outputText value="#{tag.description}" />
      </p:tab>  
    </p:tabView>

What just happened?

We have created a TabView component ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required