コンポーネント用のカスタム レンダラーを作成しh:selectOneMenu
、最終的にクラスのdescription
プロパティを利用して、 https ://stackoverflow.com/a/25512124/3280015およびhttp://baluscにある BalusC の詳細なガイドに従うための別名ツールチップを追加したいと考えています。 .blogspot.de/2008/08/styling-options-in-hselectonemenu.html .UISelectItem
title
f:selectItems
com.sun.faces.renderkit.html_basic.MenuRenderer
ここで、 を自分で拡張しCustomMenuRenderer
、 に登録してメソッドfaces-config.xml
をオーバーライドし、renderOption
オプション タグが で終了する前に次のコードを追加しましたResponsewriter
。
String titleAttributeValue = (String) component.getAttributes().get("title");
if (titleAttributeValue != null) {
String indexKey = component.getClientId(context)
+ "_currentOptionIndex";
Integer index = (Integer) component.getAttributes().get(indexKey);
if (index == null) {
index = 0;
}
component.getAttributes().put(indexKey, ++index);
}
optionClasses チュートリアルのようなリストがないため、正しいことを行っているのindexKey
か、title 属性に必要なのか、代わりに a を使用する必要があるのか はよくわかりませんが、コードはこれまでのところ機能しています!writer.writeAttribute("title", titleAttributeValue, null);
実際のビュー定義のユースケースでは、次のことを行いました。
<h:selectOneMenu value="#{cc.data}">
<f:attribute name="title" value="outerTEST" />
<c:forEach items="#{cc.list}" var="val">
<f:selectItem value="#{val}" itemValue="#{val}" itemLabel="#{val.label}">
<f:attribute name="title" value="innerTEST #{val.description}" />
</f:selectItem>
</c:forEach>
</h:selectOneMenu>
(意図を明確にするためにタイトルの値にそこを入れただけ#{val.description}
です。現在はまだ空であり、後で要素ごとに入力する方法を考える必要がありますが、質問のために、既に入力されていると想定できます。 )
しかし、今"outerTEST"
では、ブラウザで結果として得られる XHTML のオプションのタイトル属性に適切に表示されていますが、"innerTEST"
個別に表示されるべきであり、個別に表示されるべきでありselectItem
、最終的にはこれがすべてです。 .
f:selectItem
およびf:selectItems
コンポーネントには独自のレンダラーがないことは理解していますが、オプションのレンダリングは通常、そのメソッドMenuRenderer
を介してによって処理されます。renderOption
しかし、個々のタイトルを個々の selectItems に追加するにはどうすればよいでしょうか??
ありがとう