Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using negation in disabled attribute of h:selectBooleanCheckbox

Could someone please tell me how to use negation in the value of a component say checkbox to enable and disable it?

I have to disable a checkbox when the value of a property (somevalue) in bean is false.

like in

<h:selectBooleanCheckbox id="smthing" disabled="#{!somevalue}"></h:selectBooleanCheckbox>

For bean property

boolean somevalue;

should be diabled but it doesnt work. Maybe I am doing something wrong.

Also could someone please clarify if no value is assigned to the boolean what will be the case then.

like image 239
Karanveer Singh Sodhi Avatar asked Mar 27 '12 14:03

Karanveer Singh Sodhi


1 Answers

You need to reference it through the managed bean:

<h:selectBooleanCheckbox disabled="#{!bean.somevalue}" />

Another way, which is in my humble opinion prettier to read, for sure if the boolean property has a self-documenting name (somevalue isn't), is using the not keyword:

<h:selectBooleanCheckbox disabled="#{not bean.somevalue}" />

Also could someone please clarify if no value is assigned to the boolean what will be the case then.

The boolean is a primitive and just defaults to false when uninitialized as instance variable. If you have used a Boolean, it would have defaulted to null.

like image 130
BalusC Avatar answered Nov 12 '22 07:11

BalusC