複合コンポーネントをいじっていて、わからないことがありました。複合コンポーネントを使用しないと、次のようになります。
<h:outputText value="Some Label:"/>
<h:selectOneMenu">
<f:selectItem itemLabel="Item 1"/>
<f:selectItem itemLabel="Item 2"/>
<f:selectItem itemLabel="Item 3"/>
</h:selectOneMenu>
基本的に、そのスニペットを複合コンポーネントに変えました。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="label" required="true"/>
<composite:attribute name="options" required="true"/>
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<h:outputText value="#{cc.attrs.label}"/>
<h:selectOneMenu style="width:140px;">
<f:selectItem value="#{cc.attrs.options}" />
</h:selectOneMenu>
</composite:implementation>
</html>
ここで私は困惑しています。コンポーネントで使用したい項目のリストをバッキング Bean に入れて、次のように使用できることはわかっています。
<util:dropdown label="Some Label:" options="#{backingBean.list}"/>
本当の問題は、バッキング Bean を使用せずにオプションを渡す方法があるかどうかです。私は次のようなものだと思います:
<util:dropdown label="Some Label:" options="Item 1, Item 2, Item 3"/>
または多分
<util:dropdown label="Some Label:" options="#{backingBean.list}">
<f:selectItem itemLabel="Item 1"/>
<f:selectItem itemLabel="Item 2"/>
<f:selectItem itemLabel="Item 3"/>
</util:dropdown>
注:明らかに、これら2つは機能しません。そうでない場合、私は質問をしません。