Re: Getting the model

2016-04-06 Thread Ron Smits
You were right, fixed it

On Wed, Apr 6, 2016 at 6:49 PM Martin Grigorov  wrote:

> Please read the answers.
> On Apr 6, 2016 7:26 PM, "Ron Smits"  wrote:
>
> > This alas does not work:(
> >
> > First I am using wicket 7.2.0 and the getModelObject does not exist so I
> > finally made:
> >
> > @Override
> > protected void onComponentTag(ComponentTag tag) {
> > add(new AttributeAppender("class", " number"));
> > if(getDefaultModel().getObject() instanceof Number){
> > Number number = (Number) getDefaultModelObject();
> > if(number.doubleValue()<0.0)
> > add(new AttributeAppender("class", " negative"));
> >}
> > }
> >
> > This however gives the following exception:
> >
> > org.apache.wicket.WicketRuntimeException: Cannot modify component
> > hierarchy after render phase has started (page version cant change
> > then anymore)
> >  at
> > org.apache.wicket.Component.checkHierarchyChange(Component.java:3623)
> >  at org.apache.wicket.Component.addStateChange(Component.java:3538)
> >  at org.apache.wicket.Behaviors.add(Behaviors.java:55)
> >  at org.apache.wicket.Component.add(Component.java:4559)
> >  at
> >
> nl.codetribe.budget.web.common.MoneyLabel.onComponentTag(MoneyLabel.java:36)
> >  at
> > org.apache.wicket.Component.internalRenderComponent(Component.java:2521)
> >
> > On Fri, Apr 1, 2016 at 3:11 PM Tobias Soloschenko
> > tobiassolosche...@googlemail.com
> > <http://mailto:tobiassolosche...@googlemail.com> wrote:
> >
> > Cool - thanks!
> > >
> > > kind regards
> > >
> > > Tobias
> > >
> > > > Am 01.04.2016 um 14:56 schrieb Martin Grigorov  >:
> > > >
> > > > I've added an example with
> > > >
> > >
> >
> https://github.com/apache/wicket/commit/2417322673238d57a794c237e84dd5dacf890804
> > > >
> > > > I think we should explain that those are just convenience. It is
> better
> > > to
> > > > use the "old way" one cares about memory usage. I'll add it soon.
> > > >
> > > > Martin Grigorov
> > > > Wicket Training and Consulting
> > > > https://twitter.com/mtgrigorov
> > > >
> > > > On Fri, Apr 1, 2016 at 2:48 PM, Tobias Soloschenko <
> > > > tobiassolosche...@googlemail.com> wrote:
> > > >
> > > >> Hi,
> > > >>
> > > >> would be great to see some information how to use lambda models in
> the
> > > >> user guide.
> > > >>
> > > >> kind regards
> > > >>
> > > >> Tobias
> > > >>
> > > >>>> Am 01.04.2016 um 13:57 schrieb Martin Grigorov <
> > mgrigo...@apache.org
> > > >:
> > > >>>>
> > > >>>> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier 
> > wrote:
> > > >>>>
> > > >>>> Hi,
> > > >>>>
> > > >>>> yeah, of course this is right:
> > > >>>>
> > > >>>>   protected void onComponentTag(final ComponentTag tag) {
> > > >>>>
> > > >>>>   if (getModelObject().doubleValue() < 0.0) {
> > > >>>>   tag.put("class", " negative");
> > > >>>>   }
> > > >>>>   }
> > > >>>>
> > > >>>> Otherwise you'll end up with one additional behavior for each
> > render -
> > > >>>> stupid copy-paste error :/.
> > > >>>>
> > > >>>> BTW this might be an additional candidate for the new Wicket 8
> > > lambdas:
> > > >>>>
> > > >>>>   label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
> > > >>>> tag.put("class", "negative") ));
> > > >>>
> > > >>> +1
> > > >>>
> > > >>
> > > >> +1
> > > >>
> > > >>>
> > > >>>>
> > > >>>> Sven
> > > >>>>
> > > >>>>
> > > >>>>
> > > >>>>> On 31.03.2016 21:16, Martin Grigorov wrote:
> > > >>>>>
> > > >>>>> 

Re: Getting the model

2016-04-06 Thread Martin Grigorov
Please read the answers.
On Apr 6, 2016 7:26 PM, "Ron Smits"  wrote:

> This alas does not work:(
>
> First I am using wicket 7.2.0 and the getModelObject does not exist so I
> finally made:
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> add(new AttributeAppender("class", " number"));
> if(getDefaultModel().getObject() instanceof Number){
> Number number = (Number) getDefaultModelObject();
> if(number.doubleValue()<0.0)
> add(new AttributeAppender("class", " negative"));
>}
> }
>
> This however gives the following exception:
>
> org.apache.wicket.WicketRuntimeException: Cannot modify component
> hierarchy after render phase has started (page version cant change
> then anymore)
>  at
> org.apache.wicket.Component.checkHierarchyChange(Component.java:3623)
>  at org.apache.wicket.Component.addStateChange(Component.java:3538)
>  at org.apache.wicket.Behaviors.add(Behaviors.java:55)
>  at org.apache.wicket.Component.add(Component.java:4559)
>  at
> nl.codetribe.budget.web.common.MoneyLabel.onComponentTag(MoneyLabel.java:36)
>  at
> org.apache.wicket.Component.internalRenderComponent(Component.java:2521)
>
> On Fri, Apr 1, 2016 at 3:11 PM Tobias Soloschenko
> tobiassolosche...@googlemail.com
> <http://mailto:tobiassolosche...@googlemail.com> wrote:
>
> Cool - thanks!
> >
> > kind regards
> >
> > Tobias
> >
> > > Am 01.04.2016 um 14:56 schrieb Martin Grigorov :
> > >
> > > I've added an example with
> > >
> >
> https://github.com/apache/wicket/commit/2417322673238d57a794c237e84dd5dacf890804
> > >
> > > I think we should explain that those are just convenience. It is better
> > to
> > > use the "old way" one cares about memory usage. I'll add it soon.
> > >
> > > Martin Grigorov
> > > Wicket Training and Consulting
> > > https://twitter.com/mtgrigorov
> > >
> > > On Fri, Apr 1, 2016 at 2:48 PM, Tobias Soloschenko <
> > > tobiassolosche...@googlemail.com> wrote:
> > >
> > >> Hi,
> > >>
> > >> would be great to see some information how to use lambda models in the
> > >> user guide.
> > >>
> > >> kind regards
> > >>
> > >> Tobias
> > >>
> > >>>> Am 01.04.2016 um 13:57 schrieb Martin Grigorov <
> mgrigo...@apache.org
> > >:
> > >>>>
> > >>>> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier 
> wrote:
> > >>>>
> > >>>> Hi,
> > >>>>
> > >>>> yeah, of course this is right:
> > >>>>
> > >>>>   protected void onComponentTag(final ComponentTag tag) {
> > >>>>
> > >>>>   if (getModelObject().doubleValue() < 0.0) {
> > >>>>   tag.put("class", " negative");
> > >>>>   }
> > >>>>   }
> > >>>>
> > >>>> Otherwise you'll end up with one additional behavior for each
> render -
> > >>>> stupid copy-paste error :/.
> > >>>>
> > >>>> BTW this might be an additional candidate for the new Wicket 8
> > lambdas:
> > >>>>
> > >>>>   label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
> > >>>> tag.put("class", "negative") ));
> > >>>
> > >>> +1
> > >>>
> > >>
> > >> +1
> > >>
> > >>>
> > >>>>
> > >>>> Sven
> > >>>>
> > >>>>
> > >>>>
> > >>>>> On 31.03.2016 21:16, Martin Grigorov wrote:
> > >>>>>
> > >>>>> Hi,
> > >>>>>
> > >>>>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier 
> wrote:
> > >>>>>
> > >>>>> Hi,
> > >>>>>>
> > >>>>>> you can access a component's model with #getDefaultModel() or - if
> > it
> > >> is
> > >>>>>> a
> > >>>>>> generic component - with #getModel().
> > >>>>>>
> > >>>>>> To properly 'bind' to a model you should delay invocation of
> > >> #getObject()
> > &

Re: Getting the model

2016-04-06 Thread Ron Smits
This alas does not work:(

First I am using wicket 7.2.0 and the getModelObject does not exist so I
finally made:

@Override
protected void onComponentTag(ComponentTag tag) {
add(new AttributeAppender("class", " number"));
if(getDefaultModel().getObject() instanceof Number){
Number number = (Number) getDefaultModelObject();
if(number.doubleValue()<0.0)
add(new AttributeAppender("class", " negative"));
   }
}

This however gives the following exception:

org.apache.wicket.WicketRuntimeException: Cannot modify component
hierarchy after render phase has started (page version cant change
then anymore)
 at org.apache.wicket.Component.checkHierarchyChange(Component.java:3623)
 at org.apache.wicket.Component.addStateChange(Component.java:3538)
 at org.apache.wicket.Behaviors.add(Behaviors.java:55)
 at org.apache.wicket.Component.add(Component.java:4559)
 at 
nl.codetribe.budget.web.common.MoneyLabel.onComponentTag(MoneyLabel.java:36)
 at org.apache.wicket.Component.internalRenderComponent(Component.java:2521)

On Fri, Apr 1, 2016 at 3:11 PM Tobias Soloschenko
tobiassolosche...@googlemail.com
<http://mailto:tobiassolosche...@googlemail.com> wrote:

Cool - thanks!
>
> kind regards
>
> Tobias
>
> > Am 01.04.2016 um 14:56 schrieb Martin Grigorov :
> >
> > I've added an example with
> >
> https://github.com/apache/wicket/commit/2417322673238d57a794c237e84dd5dacf890804
> >
> > I think we should explain that those are just convenience. It is better
> to
> > use the "old way" one cares about memory usage. I'll add it soon.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Fri, Apr 1, 2016 at 2:48 PM, Tobias Soloschenko <
> > tobiassolosche...@googlemail.com> wrote:
> >
> >> Hi,
> >>
> >> would be great to see some information how to use lambda models in the
> >> user guide.
> >>
> >> kind regards
> >>
> >> Tobias
> >>
> >>>> Am 01.04.2016 um 13:57 schrieb Martin Grigorov  >:
> >>>>
> >>>> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier  wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> yeah, of course this is right:
> >>>>
> >>>>   protected void onComponentTag(final ComponentTag tag) {
> >>>>
> >>>>   if (getModelObject().doubleValue() < 0.0) {
> >>>>   tag.put("class", " negative");
> >>>>   }
> >>>>   }
> >>>>
> >>>> Otherwise you'll end up with one additional behavior for each render -
> >>>> stupid copy-paste error :/.
> >>>>
> >>>> BTW this might be an additional candidate for the new Wicket 8
> lambdas:
> >>>>
> >>>>   label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
> >>>> tag.put("class", "negative") ));
> >>>
> >>> +1
> >>>
> >>
> >> +1
> >>
> >>>
> >>>>
> >>>> Sven
> >>>>
> >>>>
> >>>>
> >>>>> On 31.03.2016 21:16, Martin Grigorov wrote:
> >>>>>
> >>>>> Hi,
> >>>>>
> >>>>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:
> >>>>>
> >>>>> Hi,
> >>>>>>
> >>>>>> you can access a component's model with #getDefaultModel() or - if
> it
> >> is
> >>>>>> a
> >>>>>> generic component - with #getModel().
> >>>>>>
> >>>>>> To properly 'bind' to a model you should delay invocation of
> >> #getObject()
> >>>>>> as late as possible, so better overwrite #onComponentTag():
> >>>>>>
> >>>>>>protected void onComponentTag(final ComponentTag tag) {
> >>>>>>
> >>>>>>if (getModelObject().doubleValue() < 0.0) {
> >>>>>>add(new AttributeAppender("class", " negative"));
> >>>>>>
> >>>>>> Since you are in #onComponentTag() there is no reason to add a
> >> Behavior.
> >>>>> Just use the tag: tag.append("class", "negative", " ");
> >>>>>
&

Re: Getting the model

2016-04-01 Thread Tobias Soloschenko
Cool - thanks!

kind regards

Tobias

> Am 01.04.2016 um 14:56 schrieb Martin Grigorov :
> 
> I've added an example with
> https://github.com/apache/wicket/commit/2417322673238d57a794c237e84dd5dacf890804
> 
> I think we should explain that those are just convenience. It is better to
> use the "old way" one cares about memory usage. I'll add it soon.
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Fri, Apr 1, 2016 at 2:48 PM, Tobias Soloschenko <
> tobiassolosche...@googlemail.com> wrote:
> 
>> Hi,
>> 
>> would be great to see some information how to use lambda models in the
>> user guide.
>> 
>> kind regards
>> 
>> Tobias
>> 
>>>> Am 01.04.2016 um 13:57 schrieb Martin Grigorov :
>>>> 
>>>> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier  wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> yeah, of course this is right:
>>>> 
>>>>   protected void onComponentTag(final ComponentTag tag) {
>>>> 
>>>>   if (getModelObject().doubleValue() < 0.0) {
>>>>   tag.put("class", " negative");
>>>>   }
>>>>   }
>>>> 
>>>> Otherwise you'll end up with one additional behavior for each render -
>>>> stupid copy-paste error :/.
>>>> 
>>>> BTW this might be an additional candidate for the new Wicket 8 lambdas:
>>>> 
>>>>   label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
>>>> tag.put("class", "negative") ));
>>> 
>>> +1
>>> 
>> 
>> +1
>> 
>>> 
>>>> 
>>>> Sven
>>>> 
>>>> 
>>>> 
>>>>> On 31.03.2016 21:16, Martin Grigorov wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:
>>>>> 
>>>>> Hi,
>>>>>> 
>>>>>> you can access a component's model with #getDefaultModel() or - if it
>> is
>>>>>> a
>>>>>> generic component - with #getModel().
>>>>>> 
>>>>>> To properly 'bind' to a model you should delay invocation of
>> #getObject()
>>>>>> as late as possible, so better overwrite #onComponentTag():
>>>>>> 
>>>>>>protected void onComponentTag(final ComponentTag tag) {
>>>>>> 
>>>>>>if (getModelObject().doubleValue() < 0.0) {
>>>>>>add(new AttributeAppender("class", " negative"));
>>>>>> 
>>>>>> Since you are in #onComponentTag() there is no reason to add a
>> Behavior.
>>>>> Just use the tag: tag.append("class", "negative", " ");
>>>>> 
>>>>> 
>>>>>}
>>>>>>}
>>>>>> 
>>>>>> 
>>>>>> Have fun
>>>>>> Sven
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> On 31.03.2016 16:06, Ron Smits wrote:
>>>>>> 
>>>>>> I have searched but I dont find a clear way of getting the model when
>> one
>>>>>>> is creating a custom component:
>>>>>>> 
>>>>>>> 
>>>>>>> public MoneyLabel(String id) {
>>>>>>> super(id);
>>>>>>> add(new AttributeAppender("class", " number"));
>>>>>>> }
>>>>>>> 
>>>>>>> It sounds like you always need the model.
>>>>> If there is a CompoundPropertyModel in the parents' hierarchy then move
>>>>> your logic to #onComponentTag(), as per Sven's suggestion.
>>>>> If there is no CPM in the parents then just remove this constructor.
>>>>> 
>>>>> 
>>>>> public MoneyLabel(String id, Model
>> bigDecimalModel)
>>>>>>> {
>>>>>>> super(id, bigDecimalModel);
>>>>>>> add(new AttributeAppender("class", " number"));
>>>>>>> if (bigDecimalModel.getObject().doubleValue() < 0.0) {
>>>>>>> add(new AttributeAppender("class", " negative"));
>>>>>>> }
>>>>>>> }
>>>>>>> 
>>>>>>> In the second constructor I can use the supplied model to determine
>> to
>>>>>>> add
>>>>>>> the negative class. However in the first constructor I cannot find a
>> way
>>>>>>> to
>>>>>>> access the model.
>>>>>>> 
>>>>>>> What am I missing?
>>>>>>> 
>>>>>>> Ron
>>>>>>> ​
>>>>>>> 
>>>>>>> 
>>>>>>> -
>>>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>> 
>>>> -
>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>> 
>>>> 
>> 
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Getting the model

2016-04-01 Thread Martin Grigorov
I've added an example with
https://github.com/apache/wicket/commit/2417322673238d57a794c237e84dd5dacf890804

I think we should explain that those are just convenience. It is better to
use the "old way" one cares about memory usage. I'll add it soon.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Apr 1, 2016 at 2:48 PM, Tobias Soloschenko <
tobiassolosche...@googlemail.com> wrote:

> Hi,
>
> would be great to see some information how to use lambda models in the
> user guide.
>
> kind regards
>
> Tobias
>
> > Am 01.04.2016 um 13:57 schrieb Martin Grigorov :
> >
> >> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier  wrote:
> >>
> >> Hi,
> >>
> >> yeah, of course this is right:
> >>
> >>protected void onComponentTag(final ComponentTag tag) {
> >>
> >>if (getModelObject().doubleValue() < 0.0) {
> >>tag.put("class", " negative");
> >>}
> >>}
> >>
> >> Otherwise you'll end up with one additional behavior for each render -
> >> stupid copy-paste error :/.
> >>
> >> BTW this might be an additional candidate for the new Wicket 8 lambdas:
> >>
> >>label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
> >> tag.put("class", "negative") ));
> >
> > +1
> >
>
> +1
>
> >
> >>
> >> Sven
> >>
> >>
> >>
> >>> On 31.03.2016 21:16, Martin Grigorov wrote:
> >>>
> >>> Hi,
> >>>
> >>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:
> >>>
> >>> Hi,
> >>>>
> >>>> you can access a component's model with #getDefaultModel() or - if it
> is
> >>>> a
> >>>> generic component - with #getModel().
> >>>>
> >>>> To properly 'bind' to a model you should delay invocation of
> #getObject()
> >>>> as late as possible, so better overwrite #onComponentTag():
> >>>>
> >>>> protected void onComponentTag(final ComponentTag tag) {
> >>>>
> >>>> if (getModelObject().doubleValue() < 0.0) {
> >>>> add(new AttributeAppender("class", " negative"));
> >>>>
> >>>> Since you are in #onComponentTag() there is no reason to add a
> Behavior.
> >>> Just use the tag: tag.append("class", "negative", " ");
> >>>
> >>>
> >>> }
> >>>> }
> >>>>
> >>>>
> >>>> Have fun
> >>>> Sven
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> On 31.03.2016 16:06, Ron Smits wrote:
> >>>>
> >>>> I have searched but I dont find a clear way of getting the model when
> one
> >>>>> is creating a custom component:
> >>>>>
> >>>>>
> >>>>> public MoneyLabel(String id) {
> >>>>>  super(id);
> >>>>>  add(new AttributeAppender("class", " number"));
> >>>>> }
> >>>>>
> >>>>> It sounds like you always need the model.
> >>> If there is a CompoundPropertyModel in the parents' hierarchy then move
> >>> your logic to #onComponentTag(), as per Sven's suggestion.
> >>> If there is no CPM in the parents then just remove this constructor.
> >>>
> >>>
> >>> public MoneyLabel(String id, Model
> bigDecimalModel)
> >>>>> {
> >>>>>  super(id, bigDecimalModel);
> >>>>>  add(new AttributeAppender("class", " number"));
> >>>>>  if (bigDecimalModel.getObject().doubleValue() < 0.0) {
> >>>>>  add(new AttributeAppender("class", " negative"));
> >>>>>  }
> >>>>> }
> >>>>>
> >>>>> In the second constructor I can use the supplied model to determine
> to
> >>>>> add
> >>>>> the negative class. However in the first constructor I cannot find a
> way
> >>>>> to
> >>>>> access the model.
> >>>>>
> >>>>> What am I missing?
> >>>>>
> >>>>> Ron
> >>>>> ​
> >>>>>
> >>>>>
> >>>>> -
> >>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >>>> For additional commands, e-mail: users-h...@wicket.apache.org
> >>
> >> -
> >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >> For additional commands, e-mail: users-h...@wicket.apache.org
> >>
> >>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Getting the model

2016-04-01 Thread Tobias Soloschenko
Hi,

would be great to see some information how to use lambda models in the user 
guide.

kind regards

Tobias

> Am 01.04.2016 um 13:57 schrieb Martin Grigorov :
> 
>> On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier  wrote:
>> 
>> Hi,
>> 
>> yeah, of course this is right:
>> 
>>protected void onComponentTag(final ComponentTag tag) {
>> 
>>if (getModelObject().doubleValue() < 0.0) {
>>tag.put("class", " negative");
>>}
>>}
>> 
>> Otherwise you'll end up with one additional behavior for each render -
>> stupid copy-paste error :/.
>> 
>> BTW this might be an additional candidate for the new Wicket 8 lambdas:
>> 
>>label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
>> tag.put("class", "negative") ));
> 
> +1
> 

+1

> 
>> 
>> Sven
>> 
>> 
>> 
>>> On 31.03.2016 21:16, Martin Grigorov wrote:
>>> 
>>> Hi,
>>> 
>>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:
>>> 
>>> Hi,
>>>> 
>>>> you can access a component's model with #getDefaultModel() or - if it is
>>>> a
>>>> generic component - with #getModel().
>>>> 
>>>> To properly 'bind' to a model you should delay invocation of #getObject()
>>>> as late as possible, so better overwrite #onComponentTag():
>>>> 
>>>> protected void onComponentTag(final ComponentTag tag) {
>>>> 
>>>> if (getModelObject().doubleValue() < 0.0) {
>>>> add(new AttributeAppender("class", " negative"));
>>>> 
>>>> Since you are in #onComponentTag() there is no reason to add a Behavior.
>>> Just use the tag: tag.append("class", "negative", " ");
>>> 
>>> 
>>> }
>>>> }
>>>> 
>>>> 
>>>> Have fun
>>>> Sven
>>>> 
>>>> 
>>>> 
>>>> 
>>>> On 31.03.2016 16:06, Ron Smits wrote:
>>>> 
>>>> I have searched but I dont find a clear way of getting the model when one
>>>>> is creating a custom component:
>>>>> 
>>>>> 
>>>>> public MoneyLabel(String id) {
>>>>>  super(id);
>>>>>  add(new AttributeAppender("class", " number"));
>>>>> }
>>>>> 
>>>>> It sounds like you always need the model.
>>> If there is a CompoundPropertyModel in the parents' hierarchy then move
>>> your logic to #onComponentTag(), as per Sven's suggestion.
>>> If there is no CPM in the parents then just remove this constructor.
>>> 
>>> 
>>> public MoneyLabel(String id, Model bigDecimalModel)
>>>>> {
>>>>>  super(id, bigDecimalModel);
>>>>>  add(new AttributeAppender("class", " number"));
>>>>>  if (bigDecimalModel.getObject().doubleValue() < 0.0) {
>>>>>  add(new AttributeAppender("class", " negative"));
>>>>>  }
>>>>> }
>>>>> 
>>>>> In the second constructor I can use the supplied model to determine to
>>>>> add
>>>>> the negative class. However in the first constructor I cannot find a way
>>>>> to
>>>>> access the model.
>>>>> 
>>>>> What am I missing?
>>>>> 
>>>>> Ron
>>>>> ​
>>>>> 
>>>>> 
>>>>> -
>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Getting the model

2016-04-01 Thread Martin Grigorov
On Fri, Apr 1, 2016 at 12:45 AM, Sven Meier  wrote:

> Hi,
>
> yeah, of course this is right:
>
> protected void onComponentTag(final ComponentTag tag) {
>
> if (getModelObject().doubleValue() < 0.0) {
> tag.put("class", " negative");
> }
> }
>
> Otherwise you'll end up with one additional behavior for each render -
> stupid copy-paste error :/.
>
> BTW this might be an additional candidate for the new Wicket 8 lambdas:
>
> label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0)
> tag.put("class", "negative") ));
>

+1


>
> Sven
>
>
>
> On 31.03.2016 21:16, Martin Grigorov wrote:
>
>> Hi,
>>
>> On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:
>>
>> Hi,
>>>
>>> you can access a component's model with #getDefaultModel() or - if it is
>>> a
>>> generic component - with #getModel().
>>>
>>> To properly 'bind' to a model you should delay invocation of #getObject()
>>> as late as possible, so better overwrite #onComponentTag():
>>>
>>>  protected void onComponentTag(final ComponentTag tag) {
>>>
>>>  if (getModelObject().doubleValue() < 0.0) {
>>>  add(new AttributeAppender("class", " negative"));
>>>
>>> Since you are in #onComponentTag() there is no reason to add a Behavior.
>> Just use the tag: tag.append("class", "negative", " ");
>>
>>
>>  }
>>>  }
>>>
>>>
>>> Have fun
>>> Sven
>>>
>>>
>>>
>>>
>>> On 31.03.2016 16:06, Ron Smits wrote:
>>>
>>> I have searched but I dont find a clear way of getting the model when one
>>>> is creating a custom component:
>>>>
>>>>
>>>> public MoneyLabel(String id) {
>>>>   super(id);
>>>>   add(new AttributeAppender("class", " number"));
>>>> }
>>>>
>>>> It sounds like you always need the model.
>> If there is a CompoundPropertyModel in the parents' hierarchy then move
>> your logic to #onComponentTag(), as per Sven's suggestion.
>> If there is no CPM in the parents then just remove this constructor.
>>
>>
>> public MoneyLabel(String id, Model bigDecimalModel)
>>>> {
>>>>   super(id, bigDecimalModel);
>>>>   add(new AttributeAppender("class", " number"));
>>>>   if (bigDecimalModel.getObject().doubleValue() < 0.0) {
>>>>   add(new AttributeAppender("class", " negative"));
>>>>   }
>>>> }
>>>>
>>>> In the second constructor I can use the supplied model to determine to
>>>> add
>>>> the negative class. However in the first constructor I cannot find a way
>>>> to
>>>> access the model.
>>>>
>>>> What am I missing?
>>>>
>>>> Ron
>>>> ​
>>>>
>>>>
>>>> -
>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>>> For additional commands, e-mail: users-h...@wicket.apache.org
>>>
>>>
>>>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Getting the model

2016-03-31 Thread Sven Meier

Hi,

yeah, of course this is right:

protected void onComponentTag(final ComponentTag tag) {

if (getModelObject().doubleValue() < 0.0) {
tag.put("class", " negative");
}
}

Otherwise you'll end up with one additional behavior for each render - stupid 
copy-paste error :/.

BTW this might be an additional candidate for the new Wicket 8 lambdas:

label.add(onTag(tag -> if (getModelObject().doubleValue() < 0.0) tag.put("class", 
"negative") ));

Sven


On 31.03.2016 21:16, Martin Grigorov wrote:

Hi,

On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:


Hi,

you can access a component's model with #getDefaultModel() or - if it is a
generic component - with #getModel().

To properly 'bind' to a model you should delay invocation of #getObject()
as late as possible, so better overwrite #onComponentTag():

 protected void onComponentTag(final ComponentTag tag) {

 if (getModelObject().doubleValue() < 0.0) {
 add(new AttributeAppender("class", " negative"));


Since you are in #onComponentTag() there is no reason to add a Behavior.
Just use the tag: tag.append("class", "negative", " ");



     }
     }


Have fun
Sven




On 31.03.2016 16:06, Ron Smits wrote:


I have searched but I dont find a clear way of getting the model when one
is creating a custom component:


public MoneyLabel(String id) {
  super(id);
  add(new AttributeAppender("class", " number"));
}


It sounds like you always need the model.
If there is a CompoundPropertyModel in the parents' hierarchy then move
your logic to #onComponentTag(), as per Sven's suggestion.
If there is no CPM in the parents then just remove this constructor.



public MoneyLabel(String id, Model bigDecimalModel)
{
  super(id, bigDecimalModel);
  add(new AttributeAppender("class", " number"));
  if (bigDecimalModel.getObject().doubleValue() < 0.0) {
  add(new AttributeAppender("class", " negative"));
  }
}

In the second constructor I can use the supplied model to determine to add
the negative class. However in the first constructor I cannot find a way
to
access the model.

What am I missing?

Ron
​



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org





-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Getting the model

2016-03-31 Thread Martin Grigorov
Hi,

On Thu, Mar 31, 2016 at 4:29 PM, Sven Meier  wrote:

> Hi,
>
> you can access a component's model with #getDefaultModel() or - if it is a
> generic component - with #getModel().
>
> To properly 'bind' to a model you should delay invocation of #getObject()
> as late as possible, so better overwrite #onComponentTag():
>
> protected void onComponentTag(final ComponentTag tag) {
>
> if (getModelObject().doubleValue() < 0.0) {
> add(new AttributeAppender("class", " negative"));
>

Since you are in #onComponentTag() there is no reason to add a Behavior.
Just use the tag: tag.append("class", "negative", " ");


> }
> }
>
>
> Have fun
> Sven
>
>
>
>
> On 31.03.2016 16:06, Ron Smits wrote:
>
>> I have searched but I dont find a clear way of getting the model when one
>> is creating a custom component:
>>
>>
>> public MoneyLabel(String id) {
>>  super(id);
>>  add(new AttributeAppender("class", " number"));
>> }
>>
>
It sounds like you always need the model.
If there is a CompoundPropertyModel in the parents' hierarchy then move
your logic to #onComponentTag(), as per Sven's suggestion.
If there is no CPM in the parents then just remove this constructor.


>
>> public MoneyLabel(String id, Model bigDecimalModel)
>> {
>>  super(id, bigDecimalModel);
>>  add(new AttributeAppender("class", " number"));
>>  if (bigDecimalModel.getObject().doubleValue() < 0.0) {
>>  add(new AttributeAppender("class", " negative"));
>>  }
>> }
>>
>> In the second constructor I can use the supplied model to determine to add
>> the negative class. However in the first constructor I cannot find a way
>> to
>> access the model.
>>
>> What am I missing?
>>
>> Ron
>> ​
>>
>>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Getting the model

2016-03-31 Thread Martin Makundi
2016-03-31 17:06 GMT+03:00 Ron Smits :

> I have searched but I dont find a clear way of getting the model when one
> is creating a custom component:
>
>
> public MoneyLabel(String id) {
> super(id);
> add(new AttributeAppender("class", " number"));
> }
>
> public MoneyLabel(String id, Model bigDecimalModel) {
> super(id, bigDecimalModel);
> add(new AttributeAppender("class", " number"));
> if (bigDecimalModel.getObject().doubleValue() < 0.0) {
> add(new AttributeAppender("class", " negative"));
> }
> }
>
> In the second constructor I can use the supplied model to determine to add
> the negative class. However in the first constructor I cannot find a way to
> access the model.
>
> What am I missing?
>

1. To answer your question: Is this MoneyLabel your own design? If it is
you are free to implement as you whish, or even drop the first constructor.

2. To give a recommendation on your design, I would attach the
AttributeAppender in any case and only check if the model is negative at
runtime (hollywood principle) like this:

add(new AttributeAppender("class", " negative") {

 @Override
  isEnabled(..) {
 bigDecimalModel.getObject().doubleValue() < 0.0
  }
});


**
Martin

>
> Ron
> ​
>


Re: Getting the model

2016-03-31 Thread Sven Meier

Hi,

you can access a component's model with #getDefaultModel() or - if it is 
a generic component - with #getModel().


To properly 'bind' to a model you should delay invocation of 
#getObject() as late as possible, so better overwrite #onComponentTag():


protected void onComponentTag(final ComponentTag tag) {

if (getModelObject().doubleValue() < 0.0) {
add(new AttributeAppender("class", " negative"));
}
}


Have fun
Sven



On 31.03.2016 16:06, Ron Smits wrote:

I have searched but I dont find a clear way of getting the model when one
is creating a custom component:


public MoneyLabel(String id) {
 super(id);
 add(new AttributeAppender("class", " number"));
}

public MoneyLabel(String id, Model bigDecimalModel) {
 super(id, bigDecimalModel);
 add(new AttributeAppender("class", " number"));
 if (bigDecimalModel.getObject().doubleValue() < 0.0) {
 add(new AttributeAppender("class", " negative"));
 }
}

In the second constructor I can use the supplied model to determine to add
the negative class. However in the first constructor I cannot find a way to
access the model.

What am I missing?

Ron
​




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Getting the model

2016-03-31 Thread Ron Smits
I have searched but I dont find a clear way of getting the model when one
is creating a custom component:


public MoneyLabel(String id) {
super(id);
add(new AttributeAppender("class", " number"));
}

public MoneyLabel(String id, Model bigDecimalModel) {
super(id, bigDecimalModel);
add(new AttributeAppender("class", " number"));
if (bigDecimalModel.getObject().doubleValue() < 0.0) {
add(new AttributeAppender("class", " negative"));
}
}

In the second constructor I can use the supplied model to determine to add
the negative class. However in the first constructor I cannot find a way to
access the model.

What am I missing?

Ron
​