SelectItem标签中的JSF链接

oni*_*unn 3 jsf hyperlink selectonemenu

是否有可能设置一个<a href />在我<f:selectItem itemLabel="label" />在我的链接文字是itemLabel

我正在使用普通的太阳组件.

Bal*_*usC 6

期望的结果是不是可以在HTML中.您需要为此添加JavaScript镜头.

<h:selectOneMenu onchange="window.location=this.options[this.selectedIndex].value">
    <f:selectItems value="#{bean.links}" />
<h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)

bean.getLinks()返回一个List<SelectItem>带有fullworthy URL作为项目价值.如果你想显示的联系,两者值和标签,只需使用SelectItem构造函数取一个参数.

links = new List<SelectItem>();
links.add(new SelectItem("http://google.com"));
links.add(new SelectItem("http://stackoverflow.com"));
// ...
Run Code Online (Sandbox Code Playgroud)

如果你想在视图中对它们进行硬编码,那么你当然可以抓住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>
Run Code Online (Sandbox Code Playgroud)