class InverseBooleanModel implements imodel<boolean>
 private final imodel<boolean> delegate;

  public inversebooleanmodel(imodel<boolean>delegate) {
this.delegate=delegate; }
  public boolean getobject() {
      return !delegate;
  }
  public void setobject(boolean o) {
   delegate.setobject(!o);
  }
  public void detach() {
    delegate.detach();
  }
}

add(new checkbox("cb", new inversebooleanmodel(model)));

-igor

On Fri, Apr 24, 2009 at 8:11 AM, Ryan LaHue <[email protected]> wrote:
> 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?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to