Revision: 8027
Author: rj...@google.com
Date: Mon May 3 09:01:39 2010
Log: Edit views can now display errors. Weak in that they implement
ShowErrors(Map<String, String>) rather than
ShowErrors(Map<Property<?>>, String>), but it's a start.
Review at http://gwt-code-reviews.appspot.com/444801
Review by: amitman...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8027
Modified:
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.ui.xml
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.ui.xml
/branches/2.1/bikeshed/src/com/google/gwt/valuestore/ui/RecordEditView.java
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.java
Thu Apr 29 18:58:19 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.java
Mon May 3 09:01:39 2010
@@ -17,6 +17,10 @@
import com.google.gwt.app.client.EditorSupport;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.DivElement;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.SpanElement;
+import com.google.gwt.dom.client.Style.FontWeight;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.sample.expenses.gwt.request.EmployeeRecord;
import com.google.gwt.uibinder.client.UiBinder;
@@ -31,6 +35,7 @@
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.ui.RecordEditView;
+import java.util.Map;
import java.util.Set;
/**
@@ -61,10 +66,12 @@
InlineLabel id;
@UiField
InlineLabel version;
+ @UiField
+ DivElement errors;
private Delegate delegate;
private DeltaValueStore deltas;
-
+
private EmployeeRecord record;
public EmployeeEditView() {
@@ -110,4 +117,33 @@
void onSave(@SuppressWarnings("unused") ClickEvent event) {
delegate.saveClicked();
}
-}
+
+ public void showErrors(Map<String, String> errorMap) {
+ // TODO Make EditorSupport do this
+
+ errors.setInnerText("");
+
+ if (errorMap == null || errorMap.isEmpty()) {
+ return;
+ }
+
+ Document doc = Document.get();
+ for (Map.Entry<String, String> entry : errorMap.entrySet()) {
+ /*
+ * Note that we are careful not to use setInnerHtml, to ensure we
don't
+ * render user created markup: xsite attack protection
+ */
+
+ DivElement div = doc.createDivElement();
+ div.setInnerText(" " + entry.getValue());
+
+ SpanElement name = doc.createSpanElement();
+ name.getStyle().setFontWeight(FontWeight.BOLD);
+ name.setInnerText(entry.getKey());
+
+ div.insertFirst(name);
+
+ errors.appendChild(div);
+ }
+ }
+}
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.ui.xml
Thu Apr 29 18:58:19 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditView.ui.xml
Mon May 3 09:01:39 2010
@@ -3,6 +3,7 @@
xmlns:g='urn:import:com.google.gwt.user.client.ui' >
<g:HTMLPanel>
<h3><ui:msg>Edit Employee <g:InlineLabel
ui:field='id'></g:InlineLabel> (v<g:InlineLabel
ui:field='version'/>)</ui:msg></h3>
+ <div ui:field='errors' style='background-color: red; '></div>
<div><span>Display Name:</span> <g:TextBox
ui:field='displayName'></g:TextBox></div>
<div><span>User Name:</span> <g:TextBox
ui:field='userName'></g:TextBox></div>
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.java
Thu Apr 29 18:58:19 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.java
Mon May 3 09:01:39 2010
@@ -17,6 +17,10 @@
import com.google.gwt.app.client.EditorSupport;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.DivElement;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.SpanElement;
+import com.google.gwt.dom.client.Style.FontWeight;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.sample.expenses.gwt.request.ReportRecord;
import com.google.gwt.uibinder.client.UiBinder;
@@ -31,6 +35,7 @@
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.ui.RecordEditView;
+import java.util.Map;
import java.util.Set;
/**
@@ -55,17 +60,19 @@
@UiField
TextBox approvedSupervisorKey;
@UiField
- InlineLabel created; //TODO: use a DatePicker
+ InlineLabel created; // TODO: use a DatePicker
@UiField
Button save;
@UiField
InlineLabel id;
@UiField
InlineLabel version;
+ @UiField
+ DivElement errors;
private Delegate delegate;
private DeltaValueStore deltas;
-
+
private ReportRecord record;
public ReportEditView() {
@@ -111,4 +118,33 @@
void onSave(@SuppressWarnings("unused") ClickEvent event) {
delegate.saveClicked();
}
-}
+
+ public void showErrors(Map<String, String> errorMap) {
+ // TODO Make EditorSupport do this
+
+ errors.setInnerText("");
+
+ if (errorMap == null || errorMap.isEmpty()) {
+ return;
+ }
+
+ Document doc = Document.get();
+ for (Map.Entry<String, String> entry : errorMap.entrySet()) {
+ /*
+ * Note that we are careful not to use setInnerHtml, to ensure we
don't
+ * render user created markup: xsite attack protection
+ */
+
+ DivElement div = doc.createDivElement();
+ div.setInnerText(" " + entry.getValue());
+
+ SpanElement name = doc.createSpanElement();
+ name.getStyle().setFontWeight(FontWeight.BOLD);
+ name.setInnerText(entry.getKey());
+
+ div.insertFirst(name);
+
+ errors.appendChild(div);
+ }
+ }
+}
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.ui.xml
Thu Apr 29 18:58:19 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditView.ui.xml
Mon May 3 09:01:39 2010
@@ -3,6 +3,7 @@
xmlns:g='urn:import:com.google.gwt.user.client.ui' >
<g:HTMLPanel>
<h3><ui:msg>Edit Report <g:InlineLabel ui:field='id' />
(v<g:InlineLabel ui:field='version'/>)</ui:msg></h3>
+ <div ui:field='errors' style='background-color: red; '></div>
<div><span>Purpose:</span> <g:TextBox
ui:field='purpose'></g:TextBox></div>
<div><span>Notes:</span> <g:TextBox ui:field='notes'></g:TextBox></div>
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/valuestore/ui/RecordEditView.java
Thu Apr 29 18:58:19 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/valuestore/ui/RecordEditView.java
Mon May 3 09:01:39 2010
@@ -20,6 +20,8 @@
import com.google.gwt.valuestore.shared.DeltaValueStore;
import com.google.gwt.valuestore.shared.Record;
+import java.util.Map;
+
/**
* Implemented by views that edit {...@link Record}s.
*
@@ -39,4 +41,7 @@
void setDelegate(Delegate delegate);
void setDeltaValueStore(DeltaValueStore deltas);
void setEnabled(boolean b);
-}
+
+ // TODO needs to be Map<Property<?>, String> errors
+ void showErrors(Map<String, String> errors);
+}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors