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<? 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?
Ron
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org