Jon,
FWIW,
We fought with this issue several years ago. We ended up creating a
design/framework where you allow the user to specify a "formatter" for
output when rending to the screen. IE.. So we keep the Date stored
internally as a java.sql.Date but we format it upon UI generation from the
business model.
A simple example:
http://www.planetjavainc.com/wowADDONDEV/runApp?id=121&_pj_lib=wowsamp
Example formatting code:
// Format Date with ISO
public class DateFormatterISOYearMonthDay implements IFormatter {
@Override
public String formatValue(Object value, Field field) {
if (value == null) {
// no value, return empty string
return "";
}
// create new date formatter, set up as (YearYearYearYear-MonthMonth-DayDay)
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// format the field value using the new date formatter
String s = formatter.format(value);
// return formatted value
return s;
}
}
// Format Date with Locale Default
public class LocaleSpecificDateFormatter implements IFormatter {
@Override
public String formatValue(Object value, Field field) {
if (value == null) {
// no value, return empty string
return "";
}
String dateOut;
DateFormat dateFormatter;
Locale currentLocale = Locale.getDefault(); // get default java locale
dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
currentLocale); // set DateFormat based on locale
dateOut = dateFormatter.format(value); // format value
// return formatted value
return dateOut;
}
-Paul Holm
As an Amazon Associate we earn from qualifying purchases.