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