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?

[369 byte] By [infiniteLoopa] at [2007-11-26 15:20:30]
# 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.
BalusCa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

infiniteLoopa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Then implement a valueChangeListener.
BalusCa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
if you want to use three values with that attribute, you cant use boolean. It stores only true and false.
kalania at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
I do not want to just see if the value has been changed. Basically I want the user to be able to set the value of Boolean. So he could to set it to true, false or null.
infiniteLoopa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

BalusCa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Thanks for reminding me that theres a difference. Yes I got confused. but here no java classes in schools:)
kalania at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Thanks for your help Balus.But that way a user can not easily distinguish between the values. So far I went after a selectOneMenu with options null, true and false and a Boolean converter. So far I am OK with this solution.
infiniteLoopa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.
BalusCa at 2007-7-8 11:48:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...