You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Shelli Orton <Sh...@sjrb.ca> on 2010/11/25 01:12:58 UTC

Invalid Date Using DatePicker and Short Date Format

Hi,

 

I'm having an issue using a DatePicker and hoping it's a simple fix, but
I can't find it.  I have this code:

 

public class MyPanel extends Panel

{

    Label createdDateLabel;

    DateTextField createdDateText;    

    DatePicker createdDatePicker;

 

    public MyPanel(String id)

    {

        super(id);

        ...

 

        createdDateLabel = new Label("createdDateLabel",
ResourceStrings.createdDate);

        editForm.add(createdDateLabel);

        

        createdDateText = new DateTextField("createdDateText",

                new PropertyModel<Date>(selectedPoiClliModel,
"createdDate"),

                new TimestampConverter("dd-MM-yyyy");

        createdDatePicker = new DatePicker();

        createdDatePicker.setShowOnFieldClick(true);

        createdDateText.add(createdDatePicker);        

        editForm.add(createdDateText);

        ...

    }

    ...

}

 

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());

    }

}

 

The problem is when someone chooses a date from the pop-up calendar in
the application, the time isn't set and I get this error message
displayed:

 

    '23-11-2010 HH:mm:ss' is not a valid Date.

 

I would have expected it to be defaulted to 00:00:00.  Is there some way
that I can set this?

 

Thanks for any help!

 


Re: Invalid Date Using DatePicker and Short Date Format

Posted by "nebojsa.nedic" <ne...@gmail.com>.
I am not sure about your example, but this is working and it might help.
Maybe there are better ways to do it as well.

....
String dateFormat = "dd.MM.yyyy";

DateTextField dateField = new DateTextField("date", new
PropertyModel<Date>(...), dateFormat);
startDateField.add(DateValidator.range(calMin.getTime(), calMax.getTime(),
dateFormat));//Validation
DatePicker datePickerStartDate = new DatePicker();
datePickerStartDate.setShowOnFieldClick(true);
....

Hopefully this helps...

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Invalid-Date-Using-DatePicker-and-Short-Date-Format-tp3058289p3944711.html
Sent from the Users forum 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: Invalid Date Using DatePicker and Short Date Format

Posted by david_ <me...@gmail.com>.
any help on this?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Invalid-Date-Using-DatePicker-and-Short-Date-Format-tp3058289p3943329.html
Sent from the Users forum 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