TabView surface with tabbed composite component

I want to use PrimeView 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 type 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 so far I have not succeeded in implementing a composite component that works. My approach is to create a separate customTab.xhtml file using 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>

      

However, the tabView component does not show any tabs. This is probably the case because JSF will draw a separate component for each of my: customTab-Tag. This way the tabView will not see that there is a p: tab inside my: customTab. What do I need to do to make the TabView recognize the p: tab tab inside my: customTab?

+3


source to share


1 answer


    <p:tabView>
      <p:tab>
          <ui:include src="datatabletemplate.xhtml">
             <ui:param name="data" value="#{data1}"/>
          </ui:include>
      </p:tab>
      <p:tab>
        <ui:include src="datatabletemplate.xhtml">
             <ui:param name="data" value="#{data2}"/>
          </ui:include>
      </p:tab>
      <p:tab>
         <ui:include src="datatabletemplate.xhtml">
             <ui:param name="data" value="#{data3}"/>
          </ui:include>
      </p:tab>
    </p:tabView>

      



I think this would be a quick and easy solution to the problem. Without custom components, # {data1} can be an integer bean or just a value for a datatable (or you can add additional parameters as well)

+1


source







All Articles