Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using selectBooleanCheckbox backed with an int

 
Richard Friedman
Greenhorn
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).

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

CONVERTER:
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();
}

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


FACES CONFIG:
<converter>
<converter-id>flag</converter-id>
<converter-class>[fullpath].MyConverter</converter-class>
</converter>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic