2016-03-31 17:06 GMT+03:00 Ron Smits <ron.sm...@gmail.com>:

> 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<? extends BigDecimal> 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
> ​
>

Reply via email to