You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Pablo S." <ps...@hotmail.com> on 2008/10/02 00:17:04 UTC

DefaultDataTable with date column

Hi, I would like to know how I can format a value from 1 column that is a 
date. I've a sortable dataprovider that contains my object, and one of the 
fields is a date. The html table shows the digits of the hour of the date 
(example: "00:00") instead of  something like this "2000/02/03"

Thanks
Pablo
 


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


Re: DefaultDataTable with date column

Posted by Edi <ed...@yahoo.com>.

Date format is working. But I am not able to sorting that column.

Why?

Please advise.
thanks and regards,
edi


Pablo Sca wrote:
> 
> Great!
> this is just what I need
> 
> Thanks
> Pablo
> 
> 
> --------------------------------------------------
> From: "Edgar Merino" <do...@gmail.com>
> Sent: Thursday, October 02, 2008 5:19 AM
> To: <us...@wicket.apache.org>
> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/RepeatingView%3A-add-new-component-at-specified-index-tp19739732p23478648.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: DefaultDataTable with date column

Posted by "Pablo S." <ps...@hotmail.com>.
Great!
this is just what I need

Thanks
Pablo


--------------------------------------------------
From: "Edgar Merino" <do...@gmail.com>
Sent: Thursday, October 02, 2008 5:19 AM
To: <us...@wicket.apache.org>
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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
> 

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


Re: DefaultDataTable with date column

Posted by Edgar Merino <do...@gmail.com>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DefaultDataTable with date column

Posted by Jeremy Thomerson <je...@wickettraining.com>.
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);
            }

        });

-- 
Jeremy Thomerson
http://www.wickettraining.com


On Wed, Oct 1, 2008 at 6:15 PM, Phil Grimm <ph...@gmail.com> wrote:

> Pablo,
>
> I'm displaying a date, pretty much the same way.
> But it only displays the date (eg. 9/13/08).
>        columns.add(new PropertyColumn(new Model("Publish Date"),
> "publishDate", "publishDate"));
>
> My "publishDate" field is a java.util.Date.
> I suspect the DataTable is just calling "toString()" on the Date object.
>
> Phil
>
> On Wed, Oct 1, 2008 at 5:44 PM, Pablo S. <ps...@hotmail.com> wrote:
>
> > Sorry, I have not explained more in detail.
> > I know how to format a date, but I'm using the DefaultDataTable component
> > so inside the component is filling the data taking the info from my model
> > object.
> > I have this code:
> >
> > List<IColumn<?>> columns = new ArrayList<IColumn<?>>();
> > columns.add(new PropertyColumn(new Model<String>("Delivery Date"),
> > "deliveryDate", "deliveryDate"));
> > ...
> > DefaultDataTable table = new DefaultDataTable("table", columns, new
> > SortableDocumentDataProvider(docs), 8);
> > ...
> >
> > also I have this class:
> >
> > public class SortableDocumentDataProvider extends
> > SortableDataProvider<Document>{
> > ...
> >
> > and Document has a Date property, called "deliveryDate"
> >
> > When the html is rendered, the date appears as "00:00" instead of
> > "2000/01/02". The only way I found, to solve this, is adding a String
> > property that represents the date in the format I want, but I suppose
> that
> > should exist a better solution.
> >
> > Thanks
> > Pablo
> > --------------------------------------------------
> > From: "Edgar Merino" <do...@gmail.com>
> > Sent: Wednesday, October 01, 2008 7:28 PM
> > To: <us...@wicket.apache.org>
> > Subject: Re: DefaultDataTable with date column
> >
> >
> >  Use java.text.DateFormat for that matter (take a look at
> SimpleDateFormat
> >> in case you need more control over how you want your date to be
> formatted).
> >>
> >> Edgar Merino
> >>
> >>
> >> Pablo S. escribió:
> >>
> >>> Hi, I would like to know how I can format a value from 1 column that is
> a
> >>> date. I've a sortable dataprovider that contains my object, and one of
> the
> >>> fields is a date. The html table shows the digits of the hour of the
> date
> >>> (example: "00:00") instead of  something like this "2000/02/03"
> >>>
> >>> Thanks
> >>> Pablo
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
>
> --
> Phil Grimm
> Mobile: (858) 335-3426
> Skype: philgrimm336
>

Re: DefaultDataTable with date column

Posted by Phil Grimm <ph...@gmail.com>.
Pablo,

I'm displaying a date, pretty much the same way.
But it only displays the date (eg. 9/13/08).
        columns.add(new PropertyColumn(new Model("Publish Date"),
"publishDate", "publishDate"));

My "publishDate" field is a java.util.Date.
I suspect the DataTable is just calling "toString()" on the Date object.

Phil

On Wed, Oct 1, 2008 at 5:44 PM, Pablo S. <ps...@hotmail.com> wrote:

> Sorry, I have not explained more in detail.
> I know how to format a date, but I'm using the DefaultDataTable component
> so inside the component is filling the data taking the info from my model
> object.
> I have this code:
>
> List<IColumn<?>> columns = new ArrayList<IColumn<?>>();
> columns.add(new PropertyColumn(new Model<String>("Delivery Date"),
> "deliveryDate", "deliveryDate"));
> ...
> DefaultDataTable table = new DefaultDataTable("table", columns, new
> SortableDocumentDataProvider(docs), 8);
> ...
>
> also I have this class:
>
> public class SortableDocumentDataProvider extends
> SortableDataProvider<Document>{
> ...
>
> and Document has a Date property, called "deliveryDate"
>
> When the html is rendered, the date appears as "00:00" instead of
> "2000/01/02". The only way I found, to solve this, is adding a String
> property that represents the date in the format I want, but I suppose that
> should exist a better solution.
>
> Thanks
> Pablo
> --------------------------------------------------
> From: "Edgar Merino" <do...@gmail.com>
> Sent: Wednesday, October 01, 2008 7:28 PM
> To: <us...@wicket.apache.org>
> Subject: Re: DefaultDataTable with date column
>
>
>  Use java.text.DateFormat for that matter (take a look at SimpleDateFormat
>> in case you need more control over how you want your date to be formatted).
>>
>> Edgar Merino
>>
>>
>> Pablo S. escribió:
>>
>>> Hi, I would like to know how I can format a value from 1 column that is a
>>> date. I've a sortable dataprovider that contains my object, and one of the
>>> fields is a date. The html table shows the digits of the hour of the date
>>> (example: "00:00") instead of  something like this "2000/02/03"
>>>
>>> Thanks
>>> Pablo
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Phil Grimm
Mobile: (858) 335-3426
Skype: philgrimm336

Re: DefaultDataTable with date column

Posted by "Pablo S." <ps...@hotmail.com>.
Sorry, I have not explained more in detail.
I know how to format a date, but I'm using the DefaultDataTable component so 
inside the component is filling the data taking the info from my model 
object.
I have this code:

List<IColumn<?>> columns = new ArrayList<IColumn<?>>();
columns.add(new PropertyColumn(new Model<String>("Delivery Date"), 
"deliveryDate", "deliveryDate"));
...
DefaultDataTable table = new DefaultDataTable("table", columns, new 
SortableDocumentDataProvider(docs), 8);
...

also I have this class:

public class SortableDocumentDataProvider extends 
SortableDataProvider<Document>{
...

and Document has a Date property, called "deliveryDate"

When the html is rendered, the date appears as "00:00" instead of 
"2000/01/02". The only way I found, to solve this, is adding a String 
property that represents the date in the format I want, but I suppose that 
should exist a better solution.

Thanks
Pablo
--------------------------------------------------
From: "Edgar Merino" <do...@gmail.com>
Sent: Wednesday, October 01, 2008 7:28 PM
To: <us...@wicket.apache.org>
Subject: Re: DefaultDataTable with date column

> Use java.text.DateFormat for that matter (take a look at SimpleDateFormat 
> in case you need more control over how you want your date to be 
> formatted).
>
> Edgar Merino
>
>
> Pablo S. escribió:
>> Hi, I would like to know how I can format a value from 1 column that is a 
>> date. I've a sortable dataprovider that contains my object, and one of 
>> the fields is a date. The html table shows the digits of the hour of the 
>> date (example: "00:00") instead of  something like this "2000/02/03"
>>
>> Thanks
>> Pablo
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
> 

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


Re: DefaultDataTable with date column

Posted by Edgar Merino <do...@gmail.com>.
Use java.text.DateFormat for that matter (take a look at 
SimpleDateFormat in case you need more control over how you want your 
date to be formatted).

Edgar Merino


Pablo S. escribió:
> Hi, I would like to know how I can format a value from 1 column that 
> is a date. I've a sortable dataprovider that contains my object, and 
> one of the fields is a date. The html table shows the digits of the 
> hour of the date (example: "00:00") instead of  something like this 
> "2000/02/03"
>
> Thanks
> Pablo
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


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