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:
Create a TabView component backed by server-side data and register
tabChange
andtabClose
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>