You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "r.stranders" <r....@gmail.com> on 2007/03/07 17:33:19 UTC

Three state Boolean in selectOneRadio

Hi, 

I've got the following problem. In one of my pages, I use a radiobutton to
fill a value of a Boolean attribute. However, the radiobutton has three
states: true, false, and null. Unfortunately, I cannot get selectOneRadio to
currectly set the 'null' value in my attribute when I select it. Instead,
the attribute becomes 'false'. Here is a snippet from my page:

<h:outputLabel for="enabled" value="#{messages['user.accountExpired']}" />
		<h:selectOneRadio id="enabled" value="#{criteria.accountNonExpired}">
			<f:selectItem itemValue="true"
				itemLabel="#{messages['user.accountNotExpired']}" />
			<f:selectItem itemValue="false"
				itemLabel="#{messages['user.accountExpired']}" />
			<f:selectItem itemValue="" itemLabel="#{messages['all']}" />
		</h:selectOneRadio>
<h:message errorClass="fieldError" for="enabled" />

The page is used to search for users. The radiobutton should give the user
three options: get all users, get all expired users, and get all non-expired
users.

I tried everything. Any ideas?
-- 
View this message in context: http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Three state Boolean in selectOneRadio

Posted by Paul Iov <pa...@voller-ernst.de>.
r.stranders schrieb:
> Hi, 
>
> I've got the following problem. In one of my pages, I use a radiobutton to
> fill a value of a Boolean attribute. However, the radiobutton has three
> states: true, false, and null. Unfortunately, I cannot get selectOneRadio to
> currectly set the 'null' value in my attribute when I select it. Instead,
> the attribute becomes 'false'. Here is a snippet from my page:
>
> <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}" />
> 		<h:selectOneRadio id="enabled" value="#{criteria.accountNonExpired}">
> 			<f:selectItem itemValue="true"
> 				itemLabel="#{messages['user.accountNotExpired']}" />
> 			<f:selectItem itemValue="false"
> 				itemLabel="#{messages['user.accountExpired']}" />
> 			<f:selectItem itemValue="" itemLabel="#{messages['all']}" />
> 		</h:selectOneRadio>
> <h:message errorClass="fieldError" for="enabled" />
>
> The page is used to search for users. The radiobutton should give the user
> three options: get all users, get all expired users, and get all non-expired
> users.
>
> I tried everything. Any ideas?
>   
I've run in the same problem. It's because Boolean(null) == 
Boolean.FALSE ! The only correct way to solve this should be to use 
custom converter, but unfortunately, it won't work until custom 
converters will be implemented. One possible workaround might be to use 
some logic in bean, i.e. -1=null, 0=false, 1=true. There is also some 
ADF component, which can handle this usecase.

Regards,
paul

Re: [Solved] Three state Boolean in selectOneRadio

Posted by Paul Iov <pa...@voller-ernst.de>.
Once again: it's not the BooleanConverter issue. In fact ANY converter 
dosn't work as expected, since it's just not called in component. See: 
http://issues.apache.org/jira/browse/MYFACES-1532

Regards,
paul

r.stranders schrieb:
> Thanks for your reply. I tried the converter tag to no avail. The
> BooleanConverter does indeed convert null values and empty strings to a null
> Boolean (I tried it in a simple program), but when I use it in my page it
> simply doesn't work. Moreover, I believe that the BooleanConverter is used
> by default for Boolean attributes. Anyway, it remains a strange problem,
> given the fact that BooleanConverter does work in isolation. Any other
> ideas?
>
>
> Andrew Robinson-5 wrote:
>   
>> Sorry, I think I remember that SelectItem throws an error if the value
>> is null. In JSF 1.1, if you use the boolean converter, an empty string
>> should be converted to null (javax.faces.convert.BooleanConverter).
>>
>> <h:selectOneRadio>
>>   <f:converter id="javax.faces.Boolean" />
>>   ...
>>
>> Also I assume that your bean is:
>> public Boolean getAccountNotExpired() {}
>> public void setAccountNotExpired(Boolean value) {}
>>
>> On 3/7/07, Andrew Robinson <an...@gmail.com> wrote:
>>     
>>> Guess: have you tried:
>>>
>>> <f:selectItem itemValue="#{null}" itemLabel="#{messages['all']}" />
>>>
>>> On 3/7/07, r.stranders <r....@gmail.com> wrote:
>>>       
>>>> Hi,
>>>>
>>>> I've got the following problem. In one of my pages, I use a radiobutton
>>>>         
>>> to
>>>       
>>>> fill a value of a Boolean attribute. However, the radiobutton has three
>>>> states: true, false, and null. Unfortunately, I cannot get
>>>>         
>>> selectOneRadio to
>>>       
>>>> currectly set the 'null' value in my attribute when I select it.
>>>>         
>>> Instead,
>>>       
>>>> the attribute becomes 'false'. Here is a snippet from my page:
>>>>
>>>> <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}"
>>>>         
>>> />
>>>       
>>>>                 <h:selectOneRadio id="enabled"
>>>>         
>>> value="#{criteria.accountNonExpired}">
>>>       
>>>>                         <f:selectItem itemValue="true"
>>>>                                
>>>>         
>>> itemLabel="#{messages['user.accountNotExpired']}" />
>>>       
>>>>                         <f:selectItem itemValue="false"
>>>>                                
>>>>         
>>> itemLabel="#{messages['user.accountExpired']}" />
>>>       
>>>>                         <f:selectItem itemValue=""
>>>>         
>>> itemLabel="#{messages['all']}" />
>>>       
>>>>                 </h:selectOneRadio>
>>>> <h:message errorClass="fieldError" for="enabled" />
>>>>
>>>> The page is used to search for users. The radiobutton should give the
>>>>         
>>> user
>>>       
>>>> three options: get all users, get all expired users, and get all
>>>>         
>>> non-expired
>>>       
>>>> users.
>>>>
>>>> I tried everything. Any ideas?
>>>> --
>>>> View this message in context:
>>>>         
>>> http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
>>>       
>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>>         
>>     
>
>   


Re: [Solved] Three state Boolean in selectOneRadio

Posted by "r.stranders" <r....@gmail.com>.
Thanks for your reply. I tried the converter tag to no avail. The
BooleanConverter does indeed convert null values and empty strings to a null
Boolean (I tried it in a simple program), but when I use it in my page it
simply doesn't work. Moreover, I believe that the BooleanConverter is used
by default for Boolean attributes. Anyway, it remains a strange problem,
given the fact that BooleanConverter does work in isolation. Any other
ideas?


Andrew Robinson-5 wrote:
> 
> Sorry, I think I remember that SelectItem throws an error if the value
> is null. In JSF 1.1, if you use the boolean converter, an empty string
> should be converted to null (javax.faces.convert.BooleanConverter).
> 
> <h:selectOneRadio>
>   <f:converter id="javax.faces.Boolean" />
>   ...
> 
> Also I assume that your bean is:
> public Boolean getAccountNotExpired() {}
> public void setAccountNotExpired(Boolean value) {}
> 
> On 3/7/07, Andrew Robinson <an...@gmail.com> wrote:
>> Guess: have you tried:
>>
>> <f:selectItem itemValue="#{null}" itemLabel="#{messages['all']}" />
>>
>> On 3/7/07, r.stranders <r....@gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I've got the following problem. In one of my pages, I use a radiobutton
>> to
>> > fill a value of a Boolean attribute. However, the radiobutton has three
>> > states: true, false, and null. Unfortunately, I cannot get
>> selectOneRadio to
>> > currectly set the 'null' value in my attribute when I select it.
>> Instead,
>> > the attribute becomes 'false'. Here is a snippet from my page:
>> >
>> > <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}"
>> />
>> >                 <h:selectOneRadio id="enabled"
>> value="#{criteria.accountNonExpired}">
>> >                         <f:selectItem itemValue="true"
>> >                                
>> itemLabel="#{messages['user.accountNotExpired']}" />
>> >                         <f:selectItem itemValue="false"
>> >                                
>> itemLabel="#{messages['user.accountExpired']}" />
>> >                         <f:selectItem itemValue=""
>> itemLabel="#{messages['all']}" />
>> >                 </h:selectOneRadio>
>> > <h:message errorClass="fieldError" for="enabled" />
>> >
>> > The page is used to search for users. The radiobutton should give the
>> user
>> > three options: get all users, get all expired users, and get all
>> non-expired
>> > users.
>> >
>> > I tried everything. Any ideas?
>> > --
>> > View this message in context:
>> http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
>> > Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >
>> >
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9362739
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Three state Boolean in selectOneRadio

Posted by Andrew Robinson <an...@gmail.com>.
Sorry, I think I remember that SelectItem throws an error if the value
is null. In JSF 1.1, if you use the boolean converter, an empty string
should be converted to null (javax.faces.convert.BooleanConverter).

<h:selectOneRadio>
  <f:converter id="javax.faces.Boolean" />
  ...

Also I assume that your bean is:
public Boolean getAccountNotExpired() {}
public void setAccountNotExpired(Boolean value) {}

On 3/7/07, Andrew Robinson <an...@gmail.com> wrote:
> Guess: have you tried:
>
> <f:selectItem itemValue="#{null}" itemLabel="#{messages['all']}" />
>
> On 3/7/07, r.stranders <r....@gmail.com> wrote:
> >
> > Hi,
> >
> > I've got the following problem. In one of my pages, I use a radiobutton to
> > fill a value of a Boolean attribute. However, the radiobutton has three
> > states: true, false, and null. Unfortunately, I cannot get selectOneRadio to
> > currectly set the 'null' value in my attribute when I select it. Instead,
> > the attribute becomes 'false'. Here is a snippet from my page:
> >
> > <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}" />
> >                 <h:selectOneRadio id="enabled" value="#{criteria.accountNonExpired}">
> >                         <f:selectItem itemValue="true"
> >                                 itemLabel="#{messages['user.accountNotExpired']}" />
> >                         <f:selectItem itemValue="false"
> >                                 itemLabel="#{messages['user.accountExpired']}" />
> >                         <f:selectItem itemValue="" itemLabel="#{messages['all']}" />
> >                 </h:selectOneRadio>
> > <h:message errorClass="fieldError" for="enabled" />
> >
> > The page is used to search for users. The radiobutton should give the user
> > three options: get all users, get all expired users, and get all non-expired
> > users.
> >
> > I tried everything. Any ideas?
> > --
> > View this message in context: http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
> > Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >
> >
>

Re: [Solved] Three state Boolean in selectOneRadio

Posted by "r.stranders" <r....@gmail.com>.
Yes, I did. No success...


Andrew Robinson-5 wrote:
> 
> Guess: have you tried:
> 
> <f:selectItem itemValue="#{null}" itemLabel="#{messages['all']}" />
> 
> On 3/7/07, r.stranders <r....@gmail.com> wrote:
>>
>> Hi,
>>
>> I've got the following problem. In one of my pages, I use a radiobutton
>> to
>> fill a value of a Boolean attribute. However, the radiobutton has three
>> states: true, false, and null. Unfortunately, I cannot get selectOneRadio
>> to
>> currectly set the 'null' value in my attribute when I select it. Instead,
>> the attribute becomes 'false'. Here is a snippet from my page:
>>
>> <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}"
>> />
>>                 <h:selectOneRadio id="enabled"
>> value="#{criteria.accountNonExpired}">
>>                         <f:selectItem itemValue="true"
>>                                
>> itemLabel="#{messages['user.accountNotExpired']}" />
>>                         <f:selectItem itemValue="false"
>>                                
>> itemLabel="#{messages['user.accountExpired']}" />
>>                         <f:selectItem itemValue=""
>> itemLabel="#{messages['all']}" />
>>                 </h:selectOneRadio>
>> <h:message errorClass="fieldError" for="enabled" />
>>
>> The page is used to search for users. The radiobutton should give the
>> user
>> three options: get all users, get all expired users, and get all
>> non-expired
>> users.
>>
>> I tried everything. Any ideas?
>> --
>> View this message in context:
>> http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9359418
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Three state Boolean in selectOneRadio

Posted by Andrew Robinson <an...@gmail.com>.
Guess: have you tried:

<f:selectItem itemValue="#{null}" itemLabel="#{messages['all']}" />

On 3/7/07, r.stranders <r....@gmail.com> wrote:
>
> Hi,
>
> I've got the following problem. In one of my pages, I use a radiobutton to
> fill a value of a Boolean attribute. However, the radiobutton has three
> states: true, false, and null. Unfortunately, I cannot get selectOneRadio to
> currectly set the 'null' value in my attribute when I select it. Instead,
> the attribute becomes 'false'. Here is a snippet from my page:
>
> <h:outputLabel for="enabled" value="#{messages['user.accountExpired']}" />
>                 <h:selectOneRadio id="enabled" value="#{criteria.accountNonExpired}">
>                         <f:selectItem itemValue="true"
>                                 itemLabel="#{messages['user.accountNotExpired']}" />
>                         <f:selectItem itemValue="false"
>                                 itemLabel="#{messages['user.accountExpired']}" />
>                         <f:selectItem itemValue="" itemLabel="#{messages['all']}" />
>                 </h:selectOneRadio>
> <h:message errorClass="fieldError" for="enabled" />
>
> The page is used to search for users. The radiobutton should give the user
> three options: get all users, get all expired users, and get all non-expired
> users.
>
> I tried everything. Any ideas?
> --
> View this message in context: http://www.nabble.com/Three-state-Boolean-in-selectOneRadio-tf3363241.html#a9356545
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>