This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using selectBooleanCheckbox backed with an int

Richard Friedman
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic