Thanks. I went about it differently.
I now have a TextBox and a CustomButton. Clicking on the CustomButton
brings up a DatePicker in a popup. And I give my formatters first
crack at the Date. :-)
private static final String kShortestFormat = "MM/dd";
private static final String kShortFormat = "MM/dd/yy";
public static void setupImage ()
{
gDateFormats = new ArrayList<DateTimeFormat> ();
gDateFormats.add (DateTimeFormat.getFormat (kShortestFormat));
gDateFormats.add (DateTimeFormat.getFormat (kShortFormat));
gDateFormats.add (DateTimeFormat.getShortDateFormat ());
gDateFormats.add (DateTimeFormat.getMediumDateFormat ());
gDateFormats.add (DateTimeFormat.getLongDateFormat ());
}
// Later code
if (theText.length () > 0)
{
for (DateTimeFormat parser : gDateFormats)
{
try
{
theDate = parser.parse (theText);
break;
}
catch (Exception oops)
{
// Do Nothing
}
}
}
DatePicker thePicker = new DatePicker ();
thePicker.setValue (theDate, true);
thePicker.setCurrentMonth (theDate); // HAVE to call setCurrentMonth
() to get the DatePicker to honor the value set. :-(
Greg
On Sep 6, 10:02 am, Jim Douglas <[email protected]> wrote:
> In a standard DateBox, the DatePicker is automatically visible when
> the DateBox gets focus.
>
> To change the parsing rules for dates typed by the user, you'll want
> to write a custom date parser. The basic approach is to subclass
> DateBox and do this:
>
> setFormat(new CustomDateFormat(getFormat());
> ...
> private static class CustomDateFormat extends
> DateBox.DefaultFormat
> {
> public CustomDateFormat(DateTimeFormat dateTimeFormat)
> {
> super(dateTimeFormat);
> }
>
> @Override
> public Date parse(CustomDateBox dateBox, String dateText,
> boolean reportError)
> {
> Date date = null;
> // First, see if the GWT date parser can handle it
> try
> {
> if (dateText.length() > 0)
> {
> date = getDateTimeFormat().parseStrict(dateText);
> }
> }
> catch (Exception e)
> {
>
> //http://code.google.com/p/google-web-toolkit/issues/detail?id=4633
> }
> // If GWT couldn't parse it, try my custom date parser
> if (date == null)
> {
> // custom code...parse the date however you like:
> date = customParseDate(dateText);
> }
> return date;
> }
> }
>
> On Sep 5, 7:59 pm, GregD <[email protected]> wrote:
>
> > I'm writing an app for which DateBox could be quite useful.
> > Unfortunately, its default behavior is so lacking that I can't use it,
> > unless I can fix it.
>
> > Issue 1: If I type in a month and day, instead of adding the current
> > year, it reports an error.
> > Issue 2: If I type in a date like :11/7/7, DateBox translates the date
> > as November 7, 1907.
>
> > Can I fix those behaviors? Lacking that, anyone have a date picker
> > icon I can use on a little button to bring up a DatePicker when my
> > users want to deal with one?
>
> > TIA,
>
> > Greg
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.