tags:

views:

248

answers:

1

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 components.

+4  A: 

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>
BalusC