• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using selectBooleanCheckbox backed with an int

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
reply
    Bookmark Topic Watch Topic
  • New Topic