问题
I'm trying to understand what a JSF snippet does. It goes something like this
<composite:interface>
<composite:attribute name="field" />
<composite:attribute name="value" default=""/>
[...]
</composite:interface>
<composite:implementation>
<ui:fragment rendered="some_logic_here">
<h:outputText value="#{cc.attrs.value}">
<f:attribute name="value" value="#{cc.attrs.field.value}"/>
</h:outputText>
</ui:fragment>
</composite:implementation>
The field attribute refers to a bean member that has getValue() / setValue() accessors (for a string).
The value attribute is a string that comes from elsewhere.
From what I understand, the output's value is initially set to the (static) value attribute: value="#{cc.attrs.value}", then the <f:attribute> tag sets something to the "dynamic" value retrieved from the "field" bean.
How does this work out? Does the "dynamic" value override the static one? Always?
回答1:
As you guessed, this does indeed exactly the same as:
<h:outputText value="#{cc.attrs.field.value}" />
In other words, the original developer didn't thought out it very well, or was fiddling until it started to work like magic, or perhaps had a short on coffee, or smoked something bad while developing.
来源:https://stackoverflow.com/questions/18231951/what-is-fattribute-used-for-in-this-example