开发者

JSF link in SelectItem label

Is it possible to set a <a href />around my <f:selectItem itemLabel="label" /> where my link text is the itemLabel?

I'm using the plain sun开发者_如何学C components.


The desired result is not possible in HTML. You'll need to add a shot of JavaScript for this.

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

Where bean.getLinks() returns a List<SelectItem> with a fullworthy URL as item value. If you want to show the link as both value and label, just use the SelectItem constructor taking a single argument.

links = new List<SelectItem>();
links.add(new SelectItem("http://google.com"));
links.add(new SelectItem("http://stackoverflow.com"));
// ...

If you want to hardcode them in the view, then you can of course grab 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜