Revision: 8503
Author: [email protected]
Date: Sat Aug  7 16:11:36 2010
Log: Fix datatype renderers to handle nulls properly for some primitive
types.  We now expect renderers to produce "" for null, and parsers to
return null for "".

Also works around a bug in report creation. The Created date is not be
set, and the details view cannot render a null date (because it
doesn't use renderers...). This puts us a bit out of sync with what
Roo is generating, but clears some roadblocks.

Review at http://gwt-code-reviews.appspot.com/725804

http://code.google.com/p/google-web-toolkit/source/detail?r=8503

Modified:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsView.java
 /trunk/user/src/com/google/gwt/app/client/BooleanRenderer.java
 /trunk/user/src/com/google/gwt/app/client/DoubleRenderer.java
 /trunk/user/src/com/google/gwt/app/client/IntegerRenderer.java
 /trunk/user/src/com/google/gwt/app/client/LongRenderer.java
 /trunk/user/src/com/google/gwt/i18n/client/DateTimeFormatRenderer.java
 /trunk/user/src/com/google/gwt/text/shared/AbstractRenderer.java
 /trunk/user/src/com/google/gwt/text/shared/PassthroughRenderer.java

=======================================
--- /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsView.java Fri Aug 6 11:47:57 2010 +++ /trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsView.java Sat Aug 7 16:11:36 2010
@@ -20,7 +20,7 @@
 import com.google.gwt.dom.client.SpanElement;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.HasClickHandlers;
-import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormatRenderer;
 import com.google.gwt.sample.expenses.gwt.request.ReportRecord;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
@@ -96,7 +96,7 @@
     this.record = record;
     purpose.setInnerText(record.getPurpose());
     notes.setInnerText(record.getNotes());
- created.setInnerText(DateTimeFormat.getShortDateFormat().format(record.getCreated())); + created.setInnerText(new DateTimeFormatRenderer().render(record.getCreated()));
     idSpan.setInnerText(record.getId().toString());
     versionSpan.setInnerText(record.getVersion().toString());
     reporterKey.setInnerText(String.valueOf(record.getReporterKey()));
=======================================
--- /trunk/user/src/com/google/gwt/app/client/BooleanRenderer.java Thu Jun 24 14:48:00 2010 +++ /trunk/user/src/com/google/gwt/app/client/BooleanRenderer.java Sat Aug 7 16:11:36 2010
@@ -42,6 +42,6 @@
   }

   public String render(Boolean object) {
-    return String.valueOf(object);
+    return toString(object);
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/app/client/DoubleRenderer.java Thu Jun 24 14:48:00 2010 +++ /trunk/user/src/com/google/gwt/app/client/DoubleRenderer.java Sat Aug 7 16:11:36 2010
@@ -42,6 +42,6 @@
   }

   public String render(Double object) {
-    return String.valueOf(object);
+    return toString(object);
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/app/client/IntegerRenderer.java Thu Jun 24 14:48:00 2010 +++ /trunk/user/src/com/google/gwt/app/client/IntegerRenderer.java Sat Aug 7 16:11:36 2010
@@ -42,6 +42,6 @@
   }

   public String render(Integer object) {
-    return String.valueOf(object);
+    return toString(object);
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/app/client/LongRenderer.java Thu Jun 24 14:48:00 2010 +++ /trunk/user/src/com/google/gwt/app/client/LongRenderer.java Sat Aug 7 16:11:36 2010
@@ -42,6 +42,6 @@
   }

   public String render(Long object) {
-    return String.valueOf(object);
+    return toString(object);
   }
 }
=======================================
--- /trunk/user/src/com/google/gwt/i18n/client/DateTimeFormatRenderer.java Fri Jun 18 20:16:34 2010 +++ /trunk/user/src/com/google/gwt/i18n/client/DateTimeFormatRenderer.java Sat Aug 7 16:11:36 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.i18n.client;

+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.text.shared.AbstractRenderer;

 import java.util.Date;
@@ -26,16 +27,32 @@
   private final DateTimeFormat format;
   private final TimeZone timeZone;

+  /**
+   * Create an instance using {...@link PredefinedFormat#DATE_SHORT}
+   */
+  public DateTimeFormatRenderer() {
+    this(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT));
+  }
+
+  /**
+   * Create an instance with the given format and the default time zone.
+   */
   public DateTimeFormatRenderer(DateTimeFormat format) {
     this(format, null);
   }

+  /**
+   * Create an instance with the given format and time zone.
+   */
   public DateTimeFormatRenderer(DateTimeFormat format, TimeZone timeZone) {
     this.format = format;
     this.timeZone = timeZone;
   }

   public String render(Date object) {
+    if (object == null) {
+      return toString(object);
+    }
     return timeZone == null ? format.format(object) : format.format(object,
         timeZone);
   }
=======================================
--- /trunk/user/src/com/google/gwt/text/shared/AbstractRenderer.java Fri Jun 18 20:16:34 2010 +++ /trunk/user/src/com/google/gwt/text/shared/AbstractRenderer.java Sat Aug 7 16:11:36 2010
@@ -31,4 +31,8 @@
   public void render(T object, Appendable appendable) throws IOException {
     appendable.append(render(object));
   }
-}
+
+  protected String toString(Object obj) {
+    return obj == null ? "" : String.valueOf(obj);
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/text/shared/PassthroughRenderer.java Wed Jun 30 08:56:55 2010 +++ /trunk/user/src/com/google/gwt/text/shared/PassthroughRenderer.java Sat Aug 7 16:11:36 2010
@@ -20,7 +20,8 @@
  * development, and is very likely to be deleted. Use it at your own risk.
  * </span>
  * <p>
- * A no-op String renderer.
+ * A no-op String renderer. This is rarely or never the right
+ * thing to use in production, but it's handy for tests.
  */
 public class PassthroughRenderer extends AbstractRenderer<String> {

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to