selectItemラベルのJSFリンク
-
24-09-2019 - |
質問
設定することは可能ですか? <a href />
私の周り <f:selectItem itemLabel="label" />
私のリンクテキストはどこにありますか itemLabel
?
プレーンサンコンポーネントを使用しています。
解決
望ましい結果は次のとおりです いいえ HTMLで可能です。このためにJavaScriptのショットを追加する必要があります。
<h:selectOneMenu onchange="window.location=this.options[this.selectedIndex].value">
<f:selectItems value="#{bean.links}" />
<h:selectOneMenu>
どこ bean.getLinks()
返品a List<SelectItem>
アイテムとして完全に機能するURLを使用します 価値. 。リンクを表示したい場合 両方 値とラベル、使用するだけです SelectItem
コンストラクターは単一の引数を取ります。
links = new List<SelectItem>();
links.add(new SelectItem("http://google.com"));
links.add(new SelectItem("http://stackoverflow.com"));
// ...
ビューでハードコードしたい場合は、もちろん手に入れることができます f:selectItem
:
<h:selectOneMenu onchange="window.location=this.options[this.selectedIndex].value">
<f:selectItem itemValue="http://google.com" />
<f:selectItem itemValue="http://stackoverflow.com" />
<h:selectOneMenu>
所属していません StackOverflow