You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by mallet <ry...@gmail.com> on 2009/04/24 21:49:27 UTC
Re: Reversing checkbox behavior or negating a property model
expression
Much thanks... works like a charm.
igor.vaynberg wrote:
>
> 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 <ry...@gmail.com>
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Reversing-checkbox-behavior-or-negating-a-property-model-expression-tp23218428p23223605.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Reversing checkbox behavior or negating a property model
expression
Posted by Liam Clarke-Hutchinson <li...@steelsky.co.nz>.
Sorry, AbstractCheckBoxModel.
On 4/26/09, Liam Clarke-Hutchinson <li...@steelsky.co.nz> wrote:
> Wrapping models in models is one of my favourite things about Wicket.
> :D That said, the AbstractCheckboxModel in Wicket extensions can be
> handy for one-off deviations from normal checkbox behaviour.
>
> On 4/25/09, mallet <ry...@gmail.com> wrote:
>>
>> Much thanks... works like a charm.
>>
>>
>> igor.vaynberg wrote:
>>>
>>> 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 <ry...@gmail.com>
>>> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Reversing-checkbox-behavior-or-negating-a-property-model-expression-tp23218428p23223605.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Reversing checkbox behavior or negating a property model
expression
Posted by Liam Clarke-Hutchinson <li...@steelsky.co.nz>.
Wrapping models in models is one of my favourite things about Wicket.
:D That said, the AbstractCheckboxModel in Wicket extensions can be
handy for one-off deviations from normal checkbox behaviour.
On 4/25/09, mallet <ry...@gmail.com> wrote:
>
> Much thanks... works like a charm.
>
>
> igor.vaynberg wrote:
>>
>> 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 <ry...@gmail.com>
>> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Reversing-checkbox-behavior-or-negating-a-property-model-expression-tp23218428p23223605.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org