문제

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.

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top