Reputation: 439
I have two composite components with <h:dataTable>
inside and they are differ only by content of a few <h:column>
What is the best way to escape copy-paste with possibilities of composite components? I know about tags, but we have no any tag in my project. So, it's not solution for me.
Upvotes: 0
Views: 171
Reputation: 1801
Add an attribute to your composite component:
<cc:interface>
<cc:attribute name="columnType" type="java.lang.String" required="true" />
</cc:interface>
Then in the implementation
<h:column rendered="#{cc.attrs.columnType eq 'typeAColumns'>
#{data.valueForColumnTypeA}
</h:column>
<h:column rendered="#{cc.attrs.columnType eq 'typeBColumns'>
#{data.valueForColumnTypeB}
</h:column>
You can then use it like
<my:compositeTable columnType="typeAColumns"/>
<my:compositeTable columnType="typeBColumns"/>
Upvotes: 1