According to
the docs
, “CheckBox is a two-state selection component that can be either checked or unchecked” { … } “Clicking on a check box will change its state. The state is a Boolean property that you can set with the setValue() method and obtain with the getValue() method of the Property interface”.
However, if you put a CheckBox without explicitly setting a value (that is, it will be displayed as an unchecked checkbox) with
setValue()
and retrieve its value with a
getValue()
, you realize that is value is
null
.
I understand that the Java
Boolean
class can be
null
, but what sounds unconsistent to me is that the possible value representation of the “visual representation” of an unchecked checkbox may be actually one of two possible values: false or null, thus effectively converting the CheckBox control in a
three-valuable
two-state
control.
Shouldn’t this be clearly stated in the manual? It took me some time to figure out what was happening. I think it should be noted that if no explicit value is set during CheckBox initialization,
null
is the default until it gets checked / unchecked…
This is prone to errors as actually an unchecked checkbox may mean eiter that the value is
false
or that we don’t know what the value is…
Also, unintentioned or not, the Vaadin sampler example shows a checkbox checked by default, so there’s no way to realize this behaviour from there… Shouldn’t be better to show an unchecked box by default, with a
Label
showing the current value (even without having clicked it for the 1st time), to clearly demonstrate the values it may hold?