Using negation in disabled attribute of h:selectBooleanCheckbox
Asked Answered
P

1

7

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.

Peggi answered 27/3, 2012 at 14:3 Comment(0)
S
14

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.

Six answered 27/3, 2012 at 14:7 Comment(2)
How to add html data attribute in h:selectBooleanCheckbox? That is <input type="checkbox" data-checked="4" />. Here data-checked is attribute to be added in JSF tag.Langsyne
Hello i have similar structure, but disabled="#{bookingBean.viewDisabled}" is referring to public boolean isViewDisabled(). How is that possible?Conference

© 2022 - 2024 — McMap. All rights reserved.