This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Using selectBooleanCheckbox backed with an int" Watch "Using selectBooleanCheckbox backed with an int" New topic
Author

Using selectBooleanCheckbox backed with an int

Richard Friedman
Greenhorn

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).

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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using selectBooleanCheckbox backed with an int