Using negation in a disabled h: selectBooleanCheckbox attribute

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

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

how in

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

For bean property

 boolean somevalue; 

should be allowed, but it does not work. Maybe I'm doing something wrong.

Also, someone can clarify if a value is assigned to a logical one, what will happen then.

+4
source share
1 answer

You need to access it through a managed bean:

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

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

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

Also, someone can clarify if a value is assigned to a logical one, what will happen then.

boolean is primitive and defaults to false when not initialized as an instance variable. If you used boolean , then it would be null by default.

+10
source

Source: https://habr.com/ru/post/1403670/


All Articles