Re: Format Date for PropertyColumn/DefaultDataTable

2010-10-18 Thread James Carman
We use this for formatting dates, numbers, etc.:

public class MessageFormatColumnT extends PropertyColumnT
{
private final String pattern;

public MessageFormatColumn(IModelString displayModel, String
propertyExpression, String pattern)
{
super(displayModel, propertyExpression);
this.pattern = pattern;
}

public MessageFormatColumn(IModelString displayModel, String
sortProperty, String propertyExpression, String pattern)
{
super(displayModel, sortProperty, propertyExpression);
this.pattern = pattern;
}

@Override
protected IModel? createLabelModel(IModelT itemModel)
{
IModel? superModel = super.createLabelModel(itemModel);
return new ModelString(MessageFormat.format(pattern,
superModel.getObject()));
}
}


On Mon, Oct 18, 2010 at 1:33 PM, Shelli Orton shelli.or...@sjrb.ca wrote:
 Hi,

 Is there a way to apply a DateConverter to a PropertyColumn used in a
 DefaultDataTable (and AjaxFallbackDefaultDataTable)?

 Thanks!

 Shelli

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: Format Date for PropertyColumn/DefaultDataTable

2010-10-18 Thread Shelli Orton
Hi,

Thanks for that solution!  After finding the DateLabel in the API, I
extended PropertyColumn to this class:

public class DatePropertyColumnT extends PropertyColumnT
{
private static final long serialVersionUID = 1L;
private DateConverter converter;

public DatePropertyColumn(IModelString displayModel, String
sortProperty,
String propertyExpression, DateConverter converter)
{
super(displayModel, sortProperty, propertyExpression);
this.converter = converter;
}

@SuppressWarnings(unchecked)
@Override
public void populateItem(ItemICellPopulatorT item, String
componentId, IModelT rowModel)
{
item.add(new DateLabel(componentId, (IModelDate)
createLabelModel(rowModel), converter));
}

}

I had to create my own extension of PatternDateConverter to deal with
java.sql.Timestamp values in my model objects:

public class TimestampConverter extends PatternDateConverter
{
private static final long serialVersionUID = 1L;

public TimestampConverter(String datePattern)
{
super(datePattern, false);
}

@Override
public Timestamp convertToObject(String value, Locale locale)
{
Date time = super.convertToObject(value, locale);

return new Timestamp(time.getTime());
}
}

and this is what is passed into the constructur of the
DatePropertyColumn.

Shelli


-Original Message-
From: jcar...@carmanconsulting.com [mailto:jcar...@carmanconsulting.com]
On Behalf Of James Carman
Sent: Monday, October 18, 2010 1:24 PM
To: users@wicket.apache.org
Subject: Re: Format Date for PropertyColumn/DefaultDataTable

We use this for formatting dates, numbers, etc.:

public class MessageFormatColumnT extends PropertyColumnT
{
private final String pattern;

public MessageFormatColumn(IModelString displayModel, String
propertyExpression, String pattern)
{
super(displayModel, propertyExpression);
this.pattern = pattern;
}

public MessageFormatColumn(IModelString displayModel, String
sortProperty, String propertyExpression, String pattern)
{
super(displayModel, sortProperty, propertyExpression);
this.pattern = pattern;
}

@Override
protected IModel? createLabelModel(IModelT itemModel)
{
IModel? superModel = super.createLabelModel(itemModel);
return new ModelString(MessageFormat.format(pattern,
superModel.getObject()));
}
}


On Mon, Oct 18, 2010 at 1:33 PM, Shelli Orton shelli.or...@sjrb.ca
wrote:
 Hi,

 Is there a way to apply a DateConverter to a PropertyColumn used in a
 DefaultDataTable (and AjaxFallbackDefaultDataTable)?

 Thanks!

 Shelli

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org