selectOneRadio with boolean value

UI Components for JSF
Post Reply
tcnguyen
Posts: 36
Joined: 05 Apr 2011, 13:34

03 May 2011, 10:08

PrimeFaces 3.0.M1 seems to have a problem by binding boolean value. Hier is my code:

Code: Select all

<p:selectOneRadio id="gender" value="#{user.gender}">
   <f:selectItem itemLabel="male" itemValue="true" />
   <f:selectItem itemLabel="female" itemValue="false" />
 </p:selectOneRadio>
My bean class:

Code: Select all

public class User {
	private boolean gender = true;

        // Getter/Setter
       ....
}
The setting value is not binded. Any help? Thanks
PrimeFaces 3.0.RC1 / Spring Webflow 2.3.0.RELEASE / SpringSource tc v2.1 / Tomcat 6.0.29.C.RELEASE

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

03 May 2011, 10:44

Try an Enum, that would be the better way to do this or use #{true} #{false} instead of string true / false as itemValues.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

03 May 2011, 12:07

Just wonder that JSF implicitly built-in String --> Boolean converter doesn't work here. Try to attach the boolean converter explicitly with

Code: Select all

<f:converter id="javax.faces.convert.BooleanConverter"/>
as

Code: Select all

<p:selectOneRadio id="gender" value="#{user.gender}">
   <f:selectItem itemLabel="male" itemValue="true" />
   <f:selectItem itemLabel="female" itemValue="false" />
   <f:converter id="javax.faces.convert.BooleanConverter"/>
</p:selectOneRadio>
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

tcnguyen
Posts: 36
Joined: 05 Apr 2011, 13:34

03 May 2011, 13:01

Thanks. It works by using #{true} #{false} instead.

Remark: h:selectOneRadio works also with String-value true/false
PrimeFaces 3.0.RC1 / Spring Webflow 2.3.0.RELEASE / SpringSource tc v2.1 / Tomcat 6.0.29.C.RELEASE

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests