2010-02-01 43 views
3

是否可以在我的<f:selectItem itemLabel="label" />附近設置<a href />,我的鏈接文本是itemLabelSelectItem標籤中的JSF鏈接

我使用的是簡單的太陽組件。

+1

是HTML可能期望的結果? f:selectItem的父級是什麼? – Bozho 2010-02-01 12:34:34

回答

6

期望的結果是而不是可能在HTML中。你需要爲此添加一個JavaScript鏡頭。

<h:selectOneMenu onchange="window.location=this.options[this.selectedIndex].value"> 
    <f:selectItems value="#{bean.links}" /> 
<h:selectOneMenu> 

bean.getLinks()與fullworthy URL作爲項目返回List<SelectItem>。如果您想要顯示鏈接均爲值和標籤,只需使用帶有單個參數的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>