You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "SANTINI, Rafael" <ra...@santini.eti.br> on 2009/07/21 16:53:50 UTC

: value is not a valid option

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

 


Re: : value is not a valid option

Posted by Mike Kienenberger <mk...@gmail.com>.
Maybe :)

I've never tried it that way, but it sounds reasonable.  However, I've
always wanted a more concrete type for my accessors than Number when
dealing with integer values.


On Wed, Jul 22, 2009 at 12:58 PM, Volker Weber<v....@inexso.de> wrote:
> Hi Mike,
>
> didn't this mean changing the getter/setter from Integer to Number, as
> suggested,  should help?
>
>
> Regards,
>    Volker
>
> 2009/7/21 Mike Kienenberger <mk...@gmail.com>:
>> Rather than String, try using Long for your accessors.
>>
>> By default, accessors for literals must either be String or Long or Double.
>>
>> #{1} is a new Long(1), not a new Integer(1).
>>
>> Yes, a converter will work automatically, so if you were to provide
>> #{something that evaluates to an integer}, then everything would work
>> as you expect.   But the problem is that you're not generating
>> Integers.
>>
>> But, again, El returns Longs "#{1}", Strings "1", and Doubles "#{1.1}"
>> for literals, not Integers or any other type.
>>
>> So if you had a facelets toInt() method, you could do:
>> "#{myFunction:toInteger(1)}"
>>
>> Your other option is to do what Rene suggests and provide a method
>> that returns SelectItem<Label:String,Value:Integer> select items from
>> your java code
>>
>> On Tue, Jul 21, 2009 at 1:04 PM, SANTINI, Rafael<ra...@santini.eti.br> wrote:
>>> 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" <v....@inexso.de>
>>> To: "MyFaces Discussion" <us...@myfaces.apache.org>
>>> 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 <ra...@santini.eti.br>:
>>>>
>>>> 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
>>>
>>>
>>
>
>
>
> --
> inexso - information exchange solutions GmbH
> Bismarckstraße 13      | 26122 Oldenburg
> Tel.: +49 441 4082 356 |
> FAX:  +49 441 4082 355 | www.inexso.de
>

Re: : value is not a valid option

Posted by Volker Weber <v....@inexso.de>.
Hi Mike,

didn't this mean changing the getter/setter from Integer to Number, as
suggested,  should help?


Regards,
    Volker

2009/7/21 Mike Kienenberger <mk...@gmail.com>:
> Rather than String, try using Long for your accessors.
>
> By default, accessors for literals must either be String or Long or Double.
>
> #{1} is a new Long(1), not a new Integer(1).
>
> Yes, a converter will work automatically, so if you were to provide
> #{something that evaluates to an integer}, then everything would work
> as you expect.   But the problem is that you're not generating
> Integers.
>
> But, again, El returns Longs "#{1}", Strings "1", and Doubles "#{1.1}"
> for literals, not Integers or any other type.
>
> So if you had a facelets toInt() method, you could do:
> "#{myFunction:toInteger(1)}"
>
> Your other option is to do what Rene suggests and provide a method
> that returns SelectItem<Label:String,Value:Integer> select items from
> your java code
>
> On Tue, Jul 21, 2009 at 1:04 PM, SANTINI, Rafael<ra...@santini.eti.br> wrote:
>> 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" <v....@inexso.de>
>> To: "MyFaces Discussion" <us...@myfaces.apache.org>
>> 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 <ra...@santini.eti.br>:
>>>
>>> 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
>>
>>
>



-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

Re: : value is not a valid option

Posted by "SANTINI, Rafael" <ra...@santini.eti.br>.
Mike,

Thank for you explanation about the accessors for literals! Now I understand 
why with Integer does not works.

Rafael Santini

----- Original Message ----- 
From: "Mike Kienenberger" <mk...@gmail.com>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
Sent: Tuesday, July 21, 2009 4:49 PM
Subject: Re: <t:selectOneMenu>: value is not a valid option


Rather than String, try using Long for your accessors.

By default, accessors for literals must either be String or Long or Double.

#{1} is a new Long(1), not a new Integer(1).

Yes, a converter will work automatically, so if you were to provide
#{something that evaluates to an integer}, then everything would work
as you expect.   But the problem is that you're not generating
Integers.

But, again, El returns Longs "#{1}", Strings "1", and Doubles "#{1.1}"
for literals, not Integers or any other type.

So if you had a facelets toInt() method, you could do:
"#{myFunction:toInteger(1)}"

Your other option is to do what Rene suggests and provide a method
that returns SelectItem<Label:String,Value:Integer> select items from
your java code

On Tue, Jul 21, 2009 at 1:04 PM, SANTINI, Rafael<ra...@santini.eti.br> 
wrote:
> 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" <v....@inexso.de>
> To: "MyFaces Discussion" <us...@myfaces.apache.org>
> 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 <ra...@santini.eti.br>:
>>
>> 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
>
>


Re: : value is not a valid option

Posted by Mike Kienenberger <mk...@gmail.com>.
Rather than String, try using Long for your accessors.

By default, accessors for literals must either be String or Long or Double.

#{1} is a new Long(1), not a new Integer(1).

Yes, a converter will work automatically, so if you were to provide
#{something that evaluates to an integer}, then everything would work
as you expect.   But the problem is that you're not generating
Integers.

But, again, El returns Longs "#{1}", Strings "1", and Doubles "#{1.1}"
for literals, not Integers or any other type.

So if you had a facelets toInt() method, you could do:
"#{myFunction:toInteger(1)}"

Your other option is to do what Rene suggests and provide a method
that returns SelectItem<Label:String,Value:Integer> select items from
your java code

On Tue, Jul 21, 2009 at 1:04 PM, SANTINI, Rafael<ra...@santini.eti.br> wrote:
> 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" <v....@inexso.de>
> To: "MyFaces Discussion" <us...@myfaces.apache.org>
> 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 <ra...@santini.eti.br>:
>>
>> 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
>
>

Re: : value is not a valid option

Posted by "SANTINI, Rafael" <ra...@santini.eti.br>.
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" <v....@inexso.de>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
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 <ra...@santini.eti.br>:
> 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


Re: : value is not a valid option

Posted by "SANTINI, Rafael" <ra...@santini.eti.br>.
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" <v....@inexso.de>
To: "MyFaces Discussion" <us...@myfaces.apache.org>
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 <ra...@santini.eti.br>:
> 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


Re: : value is not a valid option

Posted by Volker Weber <v....@inexso.de>.
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 <ra...@santini.eti.br>:
> 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

Re: : value is not a valid option

Posted by Anton Gavazuk <an...@gmail.com>.
Rafael,

Rene is right -
in my case JSF bean has a property with type long,
and when I was creating the values for <f:selectItems/> tag I added manually
SelectItem(0, "All") to a collection,

must be SelectItem((long)0,"All");

not sure what to do  in your case,

but I suggest to populate selectBox also by <f:selectItems/> tag




2009/7/21 Anton Gavazuk <an...@gmail.com>

> Hi Rafael,
>
> the same happens in my project, I have slight difference - I'm populating
> selectBox by <f:selectItems/> tag
> and have a strange situation - see the snippet below
>
> <select id="fm_finance_search:in_fintype" size="1" name="
> fm_finance_search:in_fintype"> <option selected="selected" value="0">All</
> option>
> <option value="7">Bill</option>
> <option value="10">Cash deposit</option>
> <option value="11">Cash withdrawal</option>
> <option value="12">Other</option>
> <option value="8">Salary payment</option>
> <option value="9">Upfront payment</option>
> </select>
>
> and when I select first "All" option jsf throws "Value is not valid",
> otherwise it works fine. Really confusing case...
>
>
> 2009/7/21 SANTINI, Rafael <ra...@santini.eti.br>
>
> 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
>>
>>
>>
>>
>

Re: : value is not a valid option

Posted by Anton Gavazuk <an...@gmail.com>.
Hi Rafael,

the same happens in my project, I have slight difference - I'm populating
selectBox by <f:selectItems/> tag
and have a strange situation - see the snippet below

<select id="fm_finance_search:in_fintype" size="1" name="
fm_finance_search:in_fintype"><option selected="selected" value="0">All</
option>
<option value="7">Bill</option>
<option value="10">Cash deposit</option>
<option value="11">Cash withdrawal</option>
<option value="12">Other</option>
<option value="8">Salary payment</option>
<option value="9">Upfront payment</option>
</select>

and when I select first "All" option jsf throws "Value is not valid",
otherwise it works fine. Really confusing case...


2009/7/21 SANTINI, Rafael <ra...@santini.eti.br>

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