Troubles with selectOneItem and a boolean value

I am new in this "JSF World"!

I am having troubles with this selectOneItem!

Here is my code

<h:selectOneMenu value="#{memberBean.member.isAmale}">

<f:selectItem itemValue="true" itemLabel="Male" />

<f:selectItem itemValue="false" itemLabel="Female" />

</h:selectOneMenu>

In my bean, member is a Member :

private Membre member;

And in my Member class, isAmale is a boolean :

privateboolean isAmale;

But, I never get the right default value and when I submit my form, I get a

Erreur de validation: Valeur not valid.

Notice : I tried the exact same code with tomahawk jars :

<t:selectOneMenu value="#{memberBean.member.isAmale}">

<f:selectItem itemValue="true" itemLabel="Male" />

<f:selectItem itemValue="false" itemLabel="Female" />

</t:selectOneMenu>

... and I get the right default value but same error when I submit the form.

Can anyone help me?

Message was edited by:

toutoune60

[1415 byte] By [toutoune60a] at [2007-10-3 6:00:52]
# 1
You're trying to store a String as a boolean which is illegal.
BalusCa at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
In fact, I tried to use converter ="javax.faces.Boolean" but got the same troubles
toutoune60a at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
The primitive boolean is not the same as the wrapper class Boolean.
BalusCa at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
hum... how can I make it work then?
toutoune60a at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Please change your member variable to String and define the getter and setter methods.Based on the string (either "true" or "false") you will have to determine what user selected.- Kiran
kirangunduraoa at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Ok thanksa lot, that works!But that does not make a clean code since getIsAmale should return a boolean!There is no way using a converter? If not, I will then use this last solution!
toutoune60a at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Don't use primitives in JSF. Use the Boolean class. Here is an example:

JSF<h:selectOneMenu value="#{myBean.selectedItem}">

<f:selectItems value="#{myBean.selectItems}" />

</h:selectOneMenu>

MyBeanprivate Boolean selectedItem;

public Boolean getSelectedItem() {

return selectedItem;

}

public void setSelectedItem(Boolean selectedItem) {

this.selectedItem = selectedItem;

}

public List getSelectItems() {

List choices = new ArrayList();

choices.add(new SelectItem(Boolean.TRUE, "Male"));

choices.add(new SelectItem(Boolean.FALSE, "Female"));

return choices;

}

BalusCa at 2007-7-15 0:42:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...