Create AccordionPanel and specify to disable a tab if no posts are associated with the tag using the disabled
attribute of the <p:tag>
element:
<p:accordionPanel value="#{tagController.tags}" var="tag" activeIndex="2"> <p:ajax event="tabChange" listener="#{tagController.onTabChange}"/> <p:tab title="#{tag.label}" disabled="#{empty tag.posts}"> <h:outputText value="#{tag.description}" /> </p:tab> </p:accordionPanel>
We have created an AccordionPanel backed by the List<Tag>
collection. We have specified disabled="#{empty tag.posts}"
to disable a tab if there are no posts associated with that tag. As there are no posts associated with struts and hibernate tags, these two tabs are disabled. Also, we have specified activeIndex="2"
to expand the third tab by default, instead of first tab: