<f:convertNumber for="...">
と<f:validator for="...">
にfor="..."
を使用できるのと同様に、次の例では、<f:attribute>
が特定のコンポーネントに適用されることをJSFに何とか伝えることができますか?f:属性が複合コンポーネントの一部に適用されることをJSFに伝えることはできますか?
<mytags:myCcInputWithValueHolder id="myparent" item="#{myBean.myDouble}" >
<f:convertNumber minFractionDigits="2" for="myinput"/>
<f:validator validatorId="bindableDoubleRangeValidator" for="myinput"/>
<f:attribute name="minimum" value="#{30.00}"/>
<f:attribute name="maximum" value="#{39.99}"/>
</mytags:myCcInputWithValueHolder>
背景:BalusC's solution to a JSF issue後
、私はカスタムバリデータを使用しています。そのバリデータにいくつかのパラメータを与えるには、<f:attribute>
が使用されます。 EditableValueHolder
で複合成分を使用する場合
次に、私は(実際には:必須)できる実際h:inputText
にバリデータを割り当てます。しかし、私はf:attribute
のために同じことをしないので、これらは代わりに呼び出し元の親コンポーネントに追加されます。たとえば:
<composite:attribute name="item" .../>
<composite:editableValueHolder name="myinput" targets="myinputtext"/>
:
<h:inputText id="myinputtext" value="#{cc.attrs.item}">
<!-- <composite:insertChildren /> doesn't change anything -->
</h:inputText>
...この記事の上部に示すように<f:validator for="myinput" ...>
で使用し、myparent:myinputtext
にバリデータを結合するが、属性がmyparent
にバインドされています。
回避策:
documentation for <f:attribute>
indeed states:
最も近い親のUIComponentカスタムアクションに関連付けられたUIComponentに属性を追加します。
そして予想通り、次の複合成分も動作する、ことを考える:
<composite:attribute name="item" .../>
<composite:attribute name="min" .../>
<composite:attribute name="max" .../>
:
<h:inputText id="myinput" value="#{cc.attrs.item}">
<f:convertNumber minFractionDigits="2"/>
<f:validator validatorId="bindableDoubleRangeValidator"/>
<f:attribute name="minimum" value="#{cc.attrs.min}"/>
<f:attribute name="maximum" value="#{cc.attrs.max}"/>
</h:inputText>
...と:また
<mytags:myCcInputWithValidator
item="#{myBean.myDouble}" min="#{30.00}" max="#{39.99}"/>
、私は簡単に親に再帰するBalusC's BindableDoubleRangeValidatorを拡張することができます値を取得するコンポーネント:
Object getAttribute(FacesContext c, UIComponent component, String name) {
Object result = component.getAttributes().get(name);
if (result == null && component.getParent() != null) {
result = getAttribute(c, component.getParent(), name);
}
return result;
}
まだ:もっと良い解決策はありますか?
と
は(そしてその間にもテスト:完璧に動作します。) – Arjan
どういたしまして。 – BalusC