Reputation: 5021
I was wondering why the <f:facet>
exists and what its benefit is as compared to just setting an attribute or declaring a child component.
For example, the <h:dataTable>
has many handy attributes like headerClass
, captionClass
, footerClass
, etc. Why could e.g. the header and footer content only be set via a <f:facet>
instead of via e.g. headerValue
or footerValue
attribute? Or perhaps as a child component?
Upvotes: 2
Views: 1826
Reputation: 1108762
For example, in a dataTable, we have many attributes for setting the header (footer, caption ...) css style, why not just adding an attribute for the value (like saying headerValue for example)?
Because you can't set JSF components as value of an attribute. Consider this:
<h:dataTable ... header="<h:outputLabel value="Search"><h:inputText ... />">
That would only end up in invalid XML.
True, it could be escaped:
<h:dataTable ... header="<h:outputLabel value="Search"><h:inputText ... />">
But this would require re-parsing of the attribute value as part of JSF component tree in order to get it actually to work. And then it has ideally to happen during view build time. JSF doesn't have facilities for that. It's simply clumsy and destroys the philosophy of JSF. Moreover, it's ugly and a maintenance pain.
Or, why not having the header (footer, ...) as child components of the dataTable ?
That's exactly what <f:facet>
does. How else should the <h:dataTable>
component know which components exactly you'd like to have to end up as header or footer?
Upvotes: 3