Symptoms: SelectBooleanCheckbox with a custom converter is throwing
java.lang.IllegalArgumentException: argument type mismatch exception. After some debugging you discover its not calling getAsObject() at all, and is apparently trying to stick a Boolean into your underlying value-binding.Set Up: The underlying binding is not a boolean (or Boolean) , but a variable of some other data type you want to have represented as a checkbox on the screen (could be a String, or a Byte as in my case). You wrote a custom converter to convert back and forth between your value and boolean, so that
getAsString() returns either true or false, and getAsObject() returns an object of your data type.Why its not working: The first Sun forum post referenced below has some justification which basically says that checkbox value is Boolean while converters are meant to be used for components that display String values. So its a problem with the specs rather than an actual bug. I don't think its a great justification (so also say other posters there).
Solution: You can change your domain data types to Boolean or have a backing bean with Boolean variable that you bind the checkbox to and then copy and convert that into the domain value.
I can't do the first, and the second is incredibly tedious, so there was really only one option (its in the second post): implement a custom renderer for the checkbox that will call the converter (if present). So you still implement the custom converter but instead of the framework the renderer calls it for you. This is totally transparent and reusable - you never have to do anything special for a certain checkbox.
Don't forget to register the renderer in faces-config.xml.
References:
http://forum.java.sun.com/thread.jspa?forumID=427&threadID=500387
http://forum.java.sun.com/thread.jspa?threadID=5205987&tstart=0
http://www.icefaces.org/JForum/posts/list/5350.page
Subj: Custom converter for HTMLSelectBooleanCheckbox not working properly - getAsObject() not called.