DateBox parseStrict

106 views
Skip to first unread message

irene zeller sancho

unread,
Sep 12, 2011, 7:12:55 AM9/12/11
to google-we...@googlegroups.com
Hi,
 
I have a problem with DateBox widget. I want to get the value with a stricted  parse, but I haven't found the way. I found some solution based on overriding the class DateBox.DefaultForm (http://permalink.gmane.org/gmane.org.google.gwt/49297), but it didn't work for me (I think because of the version).
Could somebody help me, please???
Thanks in advance!!
 
Irene Zeller

Thomas Broyer

unread,
Sep 12, 2011, 8:07:14 AM9/12/11
to google-we...@googlegroups.com
AFAICT, all you need is implement your own DateBox.Format, possibly extending DateBox.DefaultFormat, and set it on the DateBox (either passing it to the constructor, or using setFormat).

Something like:
class MyFormat extends DefaultFormat {
  @Override
  public Date parse(DateBox dateBox, String dateText, boolean reportError) {
    Date date = null;
    try {
      if (!dateText.isEmpty()) {
        date = getDateTimeFormat().parseStrict(dateText);
      }
    } catch (IllegalArgumentException iae) {
      if (reportError) {
        dateBox.addStyleName("dateBoxFormatError");
      }
    }
    return date;
  }
}

irene

unread,
Sep 13, 2011, 5:14:04 AM9/13/11
to Google Web Toolkit
Thanks you Thomas!!
It works but only in the first setter of the widget. When the blur
event occurs the function used to parse the date is other and it is
not strict. Any more idea??

Thank you!!

irene

unread,
Sep 13, 2011, 5:17:15 AM9/13/11
to Google Web Toolkit
Sorry, it was my fault and it works perfectly.
Thank you very much Thomas!

On 12 sep, 14:07, Thomas Broyer <t.bro...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages