Try something along this line
private SelectItem item;
public selectItem getItem() {
return new SelectItem(someValue, someLabel);
// someValue is your Integer and someLabel the String you want to display
// more information can be found in the Javadocs on how to use SelectItem
}
public void setItem{...}
You can also try the tag f:selectItems which expects, for example a List
containing SelectItem objects
private List<SelectItem> items;
public List<SelectItem> getItems() {
items = new ArrayList<SelectItem>();
for (Something something: AllSomeThings) {
items.add(something.getValue, something.getLabel);
}
return items;
}
with a corresponding setter if you need one.
Processing whole collections is not really a good way to proceed, but if the
collection is of a reasonable size it should give a good performance.
But is the size increases considerably this not a good option, performance wise
that is.
-----Original message-----
From: SANTINI, Rafael <[email protected]>
Sent: Tue 21-07-2009 19:04
To: MyFaces Discussion <[email protected]>;
Subject: Re: : value is not a valid option
Hi Volker,
The problem also occurrs with itemValue="#{1}".
The solution was change the getter e setter to accept and return Strings:
public String getOpcao() {
return (opcao != null ? opcao.toString() : null);
}
public void setOpcao(String opcao) {
this.opcao = Integer.valueOf(opcao);
}
But, is not there a converter for this case?
Thank you,
Rafael Santini
----- Original Message -----
From: "Volker Weber" <[email protected]>
To: "MyFaces Discussion" <[email protected]>
Sent: Tuesday, July 21, 2009 12:59 PM
Subject: Re: <t:selectOneMenu>: value is not a valid option
Hi Rafael,
your itemValues are Strings, your bean expect Integer.
you can change the getter and setter to accept and return Strings
or try itemValue="#{1}", you may need to change from Integer to Number than.
Regards,
Volker
2009/7/21 SANTINI, Rafael <[email protected]>:
> Hi,
>
> I can't figure out why the following code results in "value is not a valid
> option":
>
> <h:messages/>
> <h:form>
> <t:selectOneMenu value="#{bean.opcao}" id="opcao">
> <f:selectItem itemLabel="Opção 1" itemValue="1"/>
> <f:selectItem itemLabel="Opção 2" itemValue="2"/>
> <f:selectItem itemLabel="Opção 3" itemValue="3"/>
> </t:selectOneMenu>
> <h:message for="opcao"/>
> <h:commandButton value="OK"/>
> </h:form>
>
> public class Bean {
>
> private Integer opcao;
>
> public Integer getOpcao() {
> return opcao;
> }
>
> public void setOpcao(Integer opcao) {
> this.opcao = opcao;
> }
>
> }
>
> Thanks,
>
> Rafael Santini
>
>
>
>
--
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de