I'm scratching my head trying to figure out the best way to reverse the
behavior of a checkbox, i.e. display an unchecked box when the model behind
is true, and a checked box when the model behind is false. I don't want to
negate all my domain objects' getters/setters to accomodate this.
I was going to override the CheckBox.getConverter class to point to an
extension of CheckBoxConverter with an overridden convertToObject method and
simply reverse the:
if ("on".equals(value) || "true".equals(value))
{
return Boolean.TRUE;
}
else
{
return Boolean.FALSE;
}
Unfortunately the CheckBox.getConverter method is marked final, so this is
not a possibility. I could override the onComponentTag method but I do not
think it would be a good idea since there is a lot going on in there.
Alternatively if there was a simple way to negate the value of the
setter/getter in a PropertyModel I think that would do the trick, i.e.
new CheckBox("checkbox", new PropertyModel(domainObject, "!blue"));
Any suggestions?