Boolean object component
Hello!
I would like to set the value of a Boolean object. If I use the selectBooleanCheckbox I can only get true or false value. The problem is that I want to be able to set null value as well. So I would need something like a dropdown box with options null, true and false that vould return appropriate Boolean value. Is there a general way of doing this?
# 1
Why do you want to do this way? By spec HTML checkboxes have 2 states, not 3.If you just want to detect if the value has changed or not, use valueChangeListener.
# 2
I want to be able to store the value of an attribute and the attribute can be true, false or not set. I do not want to force the user to set the attribute.
And I could use a select box, because I know how hard it would be to show three states in the checkbox.
I just want to know if someone has done this and has a general solution.
Message was edited by:
infiniteLoop
# 6
I guess you don't understand me nor the valueChangeListener concept. Let me give a code snippet:
JSF<h:selectBooleanCheckbox value="#{myBean.booleanValue}" valueChangeListener="#{myBean.booleanListener}" />
MyBeanprivate Boolean booleanValue; // + getter + setter
public void booleanListener(ValueChangeEvent event) {
if (event.getOldValue() == null) {
booleanValue = null; // value was: Boolean.FALSE
}
}
kalani: go back to school ;) There is a difference between boolean and Boolean.
# 9
Ah so, you want the possibility to reset (null out) the Boolean value afterwards?Well, indeed go for other solutions which supports more than only 2 states. By the way, h:selectOneRadio with 3 radio buttons might also be useful.