Hi,

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

public class DatePropertyColumn<T> extends PropertyColumn<T>
{
    private static final long serialVersionUID = 1L;
    private DateConverter converter;

    public DatePropertyColumn(IModel<String> displayModel, String
sortProperty,
            String propertyExpression, DateConverter converter)
    {
        super(displayModel, sortProperty, propertyExpression);
        this.converter = converter;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public void populateItem(Item<ICellPopulator<T>> item, String
componentId, IModel<T> rowModel)
    {
        item.add(new DateLabel(componentId, (IModel<Date>)
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 MessageFormatColumn<T> extends PropertyColumn<T>
{
    private final String pattern;

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

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

    @Override
    protected IModel<?> createLabelModel(IModel<T> itemModel)
    {
        IModel<?> superModel = super.createLabelModel(itemModel);
        return new Model<String>(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

Reply via email to