Date format in DataTable
Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Date format in DataTable
Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Date format in DataTable
I do use PropertyColumn. I will try it out and let you know. Thanks for help. Wojtek Ernesto Reinaldo Barreiro pisze: Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - 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: Date format in DataTable
or public void populateItem(ItemICellPopulatorT item, String componentId, IModelT rowModel) { item.add(new Label(componentId, createLabelModel(rowModel))); } and you create directly a the label with the formated date Ernesto On Fri, Oct 30, 2009 at 1:55 PM, zabian zabia...@gmail.com wrote: I do use PropertyColumn. I will try it out and let you know. Thanks for help. Wojtek Ernesto Reinaldo Barreiro pisze: Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - 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: Date format in DataTable
It worked out. My solution is: private static final String DATE_FORMAT = -MM-dd HH:mm:ss; private static final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); ... @Override protected IModel createLabelModel(IModel rowModel) { return new ModelString(sdf.format(new PropertyModelDate(rowModel, getPropertyExpression()).getObject())); } Thank you for help. Regards, Wojtek Ernesto Reinaldo Barreiro pisze: Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - 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: Date format in DataTable
We use the following class for date columns: import org.apache.wicket.WicketRuntimeException; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; import org.apache.wicket.model.IModel; import org.joda.time.DateTime; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateTimeColumnT extends PropertyColumnT { //** // Fields //** private static final long serialVersionUID = -1285893946332340828L; private final String format; //** // Constructors //** public DateTimeColumn(IModelString displayModel, String propertyExpression, String format) { super(displayModel, propertyExpression); this.format = format; } public DateTimeColumn(IModel iModel, String sortProperty, String propertyExpression, String format) { super(iModel, sortProperty, propertyExpression); this.format = format; } //** // Other Methods //** @Override protected IModel createLabelModel(IModel iModel) { return new DateTimeModel(super.createLabelModel(iModel)); } //** // Inner Classes //** private class DateTimeModel implements IModelString { private final IModel inner; private static final long serialVersionUID = 190887916985140272L; private DateTimeModel(IModel inner) { this.inner = inner; } public void detach() { inner.detach(); } public String getObject() { DateTime dateTime = (DateTime) inner.getObject(); if(dateTime == null) { return ; } final Date date = dateTime.toDate(); SimpleDateFormat dateFormatter = new SimpleDateFormat(format); return dateFormatter.format(date); } public void setObject(String s) { SimpleDateFormat dateFormatter = new SimpleDateFormat(format); try { Date date = dateFormatter.parse(s); inner.setObject(new DateTime(date.getTime())); } catch (ParseException e) { throw new WicketRuntimeException(Unable to parse date., e ); } } } } On Fri, Oct 30, 2009 at 10:13 AM, zabian zabia...@gmail.com wrote: It worked out. My solution is: private static final String DATE_FORMAT = -MM-dd HH:mm:ss; private static final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); ... @Override protected IModel createLabelModel(IModel rowModel) { return new ModelString(sdf.format(new PropertyModelDate(rowModel, getPropertyExpression()).getObject())); } Thank you for help. Regards, Wojtek Ernesto Reinaldo Barreiro pisze: Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - 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
Re: Date format in DataTable
If you have to do the same trick in several places maybe it would be better to use James' solution. Or role a classes like public abstract class FormatedDateModel extends ModelString { private static final long serialVersionUID = 1L; private IModelDate model; public FormatedDateModel(IModelDate model) { this.model = model; } @Override public String getObject() { return getFormat().format(model.getObject()); } protected abstract DateFormat getFormat(); } public class MyFormatedDateModel extends FormatedDateModel { private static final long serialVersionUID = 1L; public FormatedDateModel(IModelDate model) { super(model) } protected DateFormat getFormat(){ return DATE_FORMAT; } } So, that you have @Override protected IModel createLabelModel(IModel rowModel) { return new MyFormatedDateModel (new PropertyModelDate(rowModel, getPropertyExpression())); } Best, Ernesto On Fri, Oct 30, 2009 at 3:13 PM, zabian zabia...@gmail.com wrote: It worked out. My solution is: private static final String DATE_FORMAT = -MM-dd HH:mm:ss; private static final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); ... @Override protected IModel createLabelModel(IModel rowModel) { return new ModelString(sdf.format(new PropertyModelDate(rowModel, getPropertyExpression()).getObject())); } Thank you for help. Regards, Wojtek Ernesto Reinaldo Barreiro pisze: Are you using PropertyColumn? If yes... Why not override protected IModel? createLabelModel(IModelT rowModel) { return new PropertyModel(rowModel, propertyExpression); } and return a model that formats the date as you need? Best, Ernesto 2009/10/30 zabian zabia...@gmail.com Hi there, i would like to find out if the date format for java.util.Date property is customizable in DataTable. Could anyone point me how to set it? Regards, Wojtek - 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