Great!
this is just what I need
Thanks
Pablo
--------------------------------------------------
From: "Edgar Merino" <[EMAIL PROTECTED]>
Sent: Thursday, October 02, 2008 5:19 AM
To: <[email protected]>
Subject: Re: DefaultDataTable with date column
Or simply use an AbstractColumn for that, you can even create a reusable
DateColumn:
public class DateColumn extends AbstractColumn {
private String datePattern; //you can have a Pattern instead
//You can overload the constructor, to have default date patterns for
example
public DateColumn(IModel columnName, String datePattern) {
super(columnName);
this.datePattern = datePattern;
}
public void populateItem(Item cellItem, String componentId, IModel
model) {
Document doc = (Document) model.getModelObject();
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getInstance();
df.applyPattern(datePattern);
cellItem.add(new Label(componentId,
df.format(doc.getDeliveryDate())));
}
}
Then just use this class as you would with any other column, along with a
pattern to apply to the format:
List<IColumn> columns = new ArrayList<IColumn>();
columns.add(new DateColumn(new Model("Delivery date"), "dd MMM yyyy '@'
hh:mm a"));
Regards,
Edgar Merino
Jeremy Thomerson escribió:
The default java.util.Date converter within Wicket has varied between
releases. I suggest adding this to the init method of your application
class and controlling the date format yourself if you need a specific
format:
((ConverterLocator) getConverterLocator()).set(Date.class, new
IConverter<Date>() {
private static final long serialVersionUID = 1L;
private final DateFormat mFormat = new
SimpleDateFormat("MM/dd/yy hh:mm:ss.SSS");
public Date convertToObject(String value, Locale locale) {
try {
return mFormat.parse(value);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public String convertToString(Date value, Locale locale) {
return mFormat.format(value);
}
});
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]