File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Using selectBooleanCheckbox backed with an int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Using selectBooleanCheckbox backed with an int" Watch "Using selectBooleanCheckbox backed with an int" New topic

Using selectBooleanCheckbox backed with an int

Richard Friedman

Joined: Mar 26, 2007
Posts: 1
I am desperately tring to use selectBooleanCheckbox backed by an int.

I havea a bean, a converter, a jsp and my faces config file. However, I can see that when populating the page the .getAsString is called just fine. And my page renders just fine. When I submit the form however my checkbox field always shows "An error occurred when processing your submitted information" as the message for that field.

Question: Is it even possible to set the value of selectBooleanCheckbox with an int field? If yes, then what are my tired eyes missing ;) If no, then why not! (I am using jsf-ri 1.2_4-b10-p01).

public int getThing() { return this.thing; }
public void setThing(int thing) { this.thing = thing; }

public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
final boolean b = Boolean.valueOf(value).booleanValue();
return (b) ? 1 : 0;

public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
if (value instanceof Number) {
int num = Integer.parseInt(((Number) value).toString());
return (num != 0) ? "true" : "false";
} else if ( value instanceof Boolean ) {
return ((Boolean) value).toString();

return Boolean.FALSE.toString();

<h:selectBooleanCheckbox id="checks" value="#{host.checks_enabled}" >
<f:converter converterId="flag" />

I agree. Here's the link:
subject: Using selectBooleanCheckbox backed with an int
It's not a secret anymore!