I want to use a PrimeFaces TabView component to display data from our server in tabs. I need three tabs to display three tables with different data.
It works if I write:
<p:tabView>
<p:tab>
// <p:dataTable> logic comes here
</p:tab>
<p:tab>
// and here
</p:tab>
</p:tabView>
My problem is that the dataTable logic is more or less the same for every tab. I don't like this kind of code duplication, so I would like to create a custom Tab that works like this:
summary.xhtml
<p:tabView>
<my:customTab dataToDisplay="#{myBean.dataSet1}">
<my:customTab dataToDisplay="#{myBean.dataSet2}">
</p:tabView>
But up to now I have not suceeded in implementing a composite component that is working. My approach is to create a separate customTab.xhtml file with this code
customTab.xhtml
<ui:composition // namespace definitions
... >
<composite:interface>
<composite:attribute name="dataToDisplay" />
</composite:interface>
<composite:implementation>
<p:tabView>
// dataTable logic comes here
</p:tabView>
</composite:implementation>
</ui:composition>
But with this the tabView component does not show any tabs. This is probably the case because JSF will draw a separate component for every my:customTab-Tag. This way the tabView will not see that there is a p:tab inside the my:customTab. What would I have to do to make the TabView recognize the p:tab inside of my:customTab ?
@RequestScoped
unless there are no ajax requests. I wanted to comment but I couldn't. I got it from here. Please correct me if I am wrong. – K Akhil