Creating subclasses is a possibility. I guess my real question is should I
subclass Label when I want a special output. Here is a different example. All
of the dates entered in my application can be marked as estimates with a
checkbox. I store the value as a Boolean as such:
private Date constructionStartDate;
private Boolean constructionStartDateEst;
When I display dates in a ListView I want to somehow flag the dates as being
estimates. I have written a method that adds a CSS class to the Label if "Est"
is true:
private Label dateToLabel(String id, Date date, Boolean dateEst) {
Label dateLabel = new Label(id, date != null ?
Time.valueOf(date).toString("M/d/yy") : "");
if (dateEst != null && dateEst.booleanValue()) {
dateLabel.add(new AttributeModifier("class", true, new
Model("dateEstimate")));
}
return dateLabel;
}
...
listItem.add(dateToLabel("startDate", project.getStartDate(),
project.getStartDateEst()));
Should this method be placed in a Util-like class or should I create a custom
DateLabel that takes these three arguments in a constructor?
Adam
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Igor Vaynberg
Sent: Friday, June 17, 2005 7:16 PM
To: [email protected]
Subject: RE: [Wicket-user] Semantic Type Conversion
Hi Howard,
You could always work it from the other angle and create two subclasses of
BigDecimal and have getters that convert on the fly in your business object
or use the two subclasses directly. That way the conversion will work
everywhere. Not sure how feasable that is in your case and how much you want
to pollute your domain model.
Igor
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Howard, Adam
Sent: Friday, June 17, 2005 5:03 PM
To: [email protected]
Subject: [Wicket-user] Semantic Type Conversion
Hi All,
I'm trying to Zen the best solution to my problem and I thought I'd check
with the list to see if anyone else has tackled this.
I have two properties in my business object that are stored as BigDecimals.
One represents money and the other a percentage. I have registered a
BigDecimal converter at the application level but these two pieces of data
should really be formatted differently when displayed in, say, a list.
I've created two IConverters, MoneyToStringConverter and
PercentToStringConverter, and I have attached them to the Label components
as such:
listItem.add(new Label("surcharge", new Model(project.getSurcharge())) {
public IConverter getConverter() {
return new MoneyToStringConverter();
}
});
listItem.add(new Label("surchargePercent", new
Model(project.getSurchargePercent())) {
public IConverter getConverter() {
return new PercentToStringConverter();
}
});
And this works. Surcharge is displayed as $50.00 and Surcharge Percent is
displayed as 50.00%. But this seems rather tedious if I have to attach these
to every field that needs conversion for display.
Does anyone have any thoughts on how we could "flag" a field or label as
being a specific semantic type? Should I create a MoneyLabel and a
PercentLabel?
Any ideas would be appreciated!
--
Adam
A language that doesn't affect the way you think about programming is not
worth knowing.
-- Alan J. Perlis
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from
IBM. Find simple to follow Roadmaps, straightforward articles, informative
Webcasts and more! Get everything you need to get up to speed, fast.
http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user