Public: Start of a sample application showing GWT validation.

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

Review by: robertvawter@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@8656 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/build.xml b/samples/build.xml
index 6676020..ba36617 100644
--- a/samples/build.xml
+++ b/samples/build.xml
@@ -38,6 +38,10 @@
     <gwt.ant dir="showcase" />
   </target>
 
+  <target name="validation" description="Build validation">
+    <gwt.ant dir="validation" />
+  </target>
+
   <target name="-do" description="Run all subprojects" >
     <antcall target="dynatable" />
     <antcall target="dynatablerf" />
@@ -47,6 +51,7 @@
     <!-- <antcall target="logexample" /> Doesn't quite work yet -->
     <antcall target="mail" />
     <antcall target="showcase" />
+    <antcall target="validation" />
   </target>
 
   <target name="build" description="Builds GWT">
@@ -72,7 +77,7 @@
       <param name="target" value="source" />
     </antcall>
   </target>
-  
+
   <target name="test" description="Test GWT">
     <antcall target="-do">
       <param name="target" value="test" />
diff --git a/samples/validation/build.xml b/samples/validation/build.xml
new file mode 100755
index 0000000..a537a27
--- /dev/null
+++ b/samples/validation/build.xml
@@ -0,0 +1,5 @@
+<project name="validation" default="build" basedir=".">
+  <property name="sample.root" value="validation" />
+  <property name="sample.module" value="Validation" />
+  <import file="../common.ant.xml" />
+</project>
diff --git a/samples/validation/src/com/google/gwt/sample/validation/COPYING b/samples/validation/src/com/google/gwt/sample/validation/COPYING
new file mode 100644
index 0000000..d9a10c0
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/COPYING
@@ -0,0 +1,176 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
diff --git a/samples/validation/src/com/google/gwt/sample/validation/Validation.gwt.xml b/samples/validation/src/com/google/gwt/sample/validation/Validation.gwt.xml
new file mode 100644
index 0000000..120c92d
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/Validation.gwt.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2010 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+
+<module rename-to='validation'>
+  <inherits name='com.google.gwt.rpc.RPC'/>
+  <inherits name='com.google.gwt.user.User'/>
+  <inherits name='com.google.gwt.user.theme.standard.Standard'/>
+
+  <entry-point class='com.google.gwt.sample.validation.client.Validation'/>
+
+  <source path='client'/>
+  <source path='shared'/>
+</module>
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/GreetingService.java b/samples/validation/src/com/google/gwt/sample/validation/client/GreetingService.java
new file mode 100644
index 0000000..41f61f4
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/GreetingService.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.client;
+
+import com.google.gwt.rpc.client.RpcService;
+import com.google.gwt.sample.validation.shared.Person;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+/**
+ * The client side stub for the RPC service.
+ */
+@RemoteServiceRelativePath("greet")
+public interface GreetingService extends RpcService {
+  String greetServer(Person name) throws IllegalArgumentException;
+}
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/GreetingServiceAsync.java b/samples/validation/src/com/google/gwt/sample/validation/client/GreetingServiceAsync.java
new file mode 100644
index 0000000..cbc3b97
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/GreetingServiceAsync.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.client;
+
+import com.google.gwt.sample.validation.shared.Person;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+/**
+ * The async counterpart of <code>GreetingService</code>.
+ */
+public interface GreetingServiceAsync {
+  void greetServer(Person person, AsyncCallback<String> callback)
+      throws IllegalArgumentException;
+}
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/Validation.java b/samples/validation/src/com/google/gwt/sample/validation/client/Validation.java
new file mode 100644
index 0000000..6a33243
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/Validation.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.client;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.sample.validation.shared.Person;
+import com.google.gwt.user.client.ui.RootPanel;
+
+/**
+ * Entry point classes define <code>onModuleLoad()</code>.
+ */
+public class Validation implements EntryPoint {
+
+  /**
+   * Create a remote service proxy to talk to the server-side Greeting service.
+   */
+  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
+
+
+  /**
+   * This is the entry point method.
+   */
+  public void onModuleLoad() {
+
+    Person person = new Person();
+    ValidationView view = new ValidationView(person, greetingService);
+    RootPanel.get("view").add(view);
+  }
+}
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.java b/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.java
new file mode 100644
index 0000000..37635e0
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2010 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.event.dom.client.KeyUpEvent;
+import com.google.gwt.resources.client.CssResource;
+import com.google.gwt.sample.validation.shared.Person;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.uibinder.client.UiHandler;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.DialogBox;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * Display the Validation sample.
+ */
+public class ValidationView extends Composite {
+  interface MyStyle extends CssResource {
+    String error();
+  }
+
+  interface ValidationViewUiBinder extends UiBinder<Widget, ValidationView> {
+  }
+
+  /**
+   * The message displayed to the user when the server cannot be reached or
+   * returns an error.
+   */
+  private static final String SERVER_ERROR = "An error occurred while "
+      + "attempting to contact the server. Please check your network "
+      + "connection and try again.";
+
+  private static ValidationViewUiBinder uiBinder = GWT.create(ValidationViewUiBinder.class);
+
+  @UiField
+  Button closeButton;
+
+  @UiField
+  DialogBox dialogBox;
+
+  @UiField
+  Label errorLabel;
+
+  @UiField
+  TextBox nameField;
+
+  @UiField
+  Button sendButton;
+
+  @UiField
+  HTML serverResponse;
+
+  @UiField
+  MyStyle style;
+
+  @UiField
+  Label textToServer;
+
+  private final GreetingServiceAsync greetingService;
+
+  private final Person person;
+
+  public ValidationView(Person person, GreetingServiceAsync greetingService) {
+
+    this.person = person;
+
+    this.greetingService = greetingService;
+    initWidget(uiBinder.createAndBindUi(this));
+
+    nameField.setText(person.getName());
+  }
+
+  @UiHandler("closeButton")
+  public void doClick(ClickEvent e) {
+    dialogBox.hide();
+    sendButton.setEnabled(true);
+    sendButton.setFocus(true);
+  }
+
+  @UiHandler("sendButton")
+  void onClick(ClickEvent e) {
+    sendPersonToServer();
+  }
+
+  @UiHandler("sendButton")
+  void onKeyPress(KeyUpEvent e) {
+    if (e.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
+      sendPersonToServer();
+    }
+  }
+
+  /**
+   * Send the person from the nameField to the server and wait for a response.
+   */
+  private void sendPersonToServer() {
+    errorLabel.setText("");
+    person.setName(nameField.getText());
+
+    // TODO(nchalko) validate.
+
+    sendButton.setEnabled(false);
+    textToServer.setText(person.getName());
+    serverResponse.setText("");
+    greetingService.greetServer(person, new AsyncCallback<String>() {
+      public void onFailure(Throwable caught) {
+        // Show the RPC error message to the user
+        dialogBox.setText("Remote Procedure Call - Failure");
+        serverResponse.addStyleName(style.error());
+        serverResponse.setHTML(SERVER_ERROR);
+        dialogBox.center();
+        closeButton.setFocus(true);
+      }
+
+      public void onSuccess(String result) {
+        dialogBox.setText("Remote Procedure Call");
+        serverResponse.removeStyleName(style.error());
+        serverResponse.setHTML(result);
+        dialogBox.center();
+        closeButton.setFocus(true);
+      }
+    });
+  }
+}
diff --git a/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.ui.xml b/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.ui.xml
new file mode 100644
index 0000000..dc7c5a6
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/client/ValidationView.ui.xml
@@ -0,0 +1,52 @@
+<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
+<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
+  xmlns:g="urn:import:com.google.gwt.user.client.ui">
+  <ui:style type ="com.google.gwt.sample.validation.client.ValidationView.MyStyle">
+    @external .gwt-DialogBox;
+    .gwt-DialogBox {
+      width: 400px;
+    }
+    .panel {
+      align: center;
+    }
+    .send {
+      display: block;
+      font-size: 16pt;
+    }
+    .error {
+      color: red;
+    }
+    .dialogPanel {
+      margin: 5px;
+    }
+    .close {
+      margin: 15px 6px 6px;
+    }
+  </ui:style>
+  <g:VerticalPanel styleName="{style.panel}">
+    <g:FlowPanel>
+      <g:Label>Please enter your name:</g:Label>
+      <g:TextBox ui:field="nameField">GWT User</g:TextBox>
+    </g:FlowPanel>
+    <g:Button styleName="{style.send}" ui:field="sendButton">Send</g:Button>
+    <g:Label styleName="{style.error}" ui:field="errorLabel" />
+    <g:DialogBox ui:field="dialogBox"
+        animationEnabled="true"
+        text="Remote Procedure Call"
+        visible="false"
+        width="400">
+      <g:VerticalPanel styleName="dialogPanel">
+        <g:HTML>
+          <b>Sending name to the server:</b>
+        </g:HTML>
+        <g:Label ui:field="textToServer" />
+        <g:HTML>
+          <br />
+          <b>Server replies:</b>
+        </g:HTML>
+        <g:HTML ui:field="serverResponse" />
+        <g:Button styleName="{style.close}" ui:field="closeButton">Close</g:Button>
+      </g:VerticalPanel>
+    </g:DialogBox>
+  </g:VerticalPanel>
+</ui:UiBinder>
\ No newline at end of file
diff --git a/samples/validation/src/com/google/gwt/sample/validation/server/GreetingServiceImpl.java b/samples/validation/src/com/google/gwt/sample/validation/server/GreetingServiceImpl.java
new file mode 100644
index 0000000..00a2bd8
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/server/GreetingServiceImpl.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.server;
+
+import com.google.gwt.rpc.server.RpcServlet;
+import com.google.gwt.sample.validation.client.GreetingService;
+import com.google.gwt.sample.validation.shared.Person;
+
+/**
+ * The server side implementation of the RPC service.
+ */
+@SuppressWarnings("serial")
+public class GreetingServiceImpl extends RpcServlet implements
+    GreetingService {
+
+  public String greetServer(Person person) throws IllegalArgumentException {
+    // Verify that the input is valid.
+
+    // TODO(nchalko) validate
+
+    String serverInfo = getServletContext().getServerInfo();
+    String userAgent = getThreadLocalRequest().getHeader("User-Agent");
+
+    // Escape data from the client to avoid cross-site script vulnerabilities.
+    String value = escapeHtml(person.getName());
+    userAgent = escapeHtml(userAgent);
+
+    return "Hello, " + value + "!<br><br>I am running " + serverInfo
+        + ".<br><br>It looks like you are using:<br>" + userAgent;
+  }
+
+  /**
+   * Escape an html string. Escaping data received from the client helps to
+   * prevent cross-site script vulnerabilities.
+   *
+   * @param html the html string to escape
+   * @return the escaped string
+   */
+  private String escapeHtml(String html) {
+    // TODO(nchalko) use SafeHtml after it's integrated.
+    if (html == null) {
+      return null;
+    }
+    return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(
+        ">", "&gt;");
+  }
+}
diff --git a/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java b/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java
new file mode 100644
index 0000000..27d196b
--- /dev/null
+++ b/samples/validation/src/com/google/gwt/sample/validation/shared/Person.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.sample.validation.shared;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * A sample bean to show validation on.
+ */
+public class Person implements IsSerializable {
+
+  @NotNull
+  @Size(min = 4)
+  private String name;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+}
diff --git a/samples/validation/war/Validation.css b/samples/validation/war/Validation.css
new file mode 100644
index 0000000..ebf683e
--- /dev/null
+++ b/samples/validation/war/Validation.css
@@ -0,0 +1,15 @@
+/** Add css rules here for your application. */
+
+
+/** Example rules used by the template application (remove for your app) */
+h1 {
+  font-size: 2em;
+  font-weight: bold;
+  color: #777777;
+  margin: 40px 0px 70px;
+  text-align: center;
+}
+
+.serverResponseLabelError {
+  color: red;
+}
diff --git a/samples/validation/war/Validation.html b/samples/validation/war/Validation.html
new file mode 100644
index 0000000..32654de
--- /dev/null
+++ b/samples/validation/war/Validation.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--                                                                        -->
+<!-- Copyright 2010 Google Inc.                                             -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you    -->
+<!-- may not use this file except in compliance with the License. You may   -->
+<!-- may obtain a copy of the License at                                    -->
+<!--                                                                        -->
+<!-- http://www.apache.org/licenses/LICENSE-2.0                             -->
+<!--                                                                        -->
+<!-- Unless required by applicable law or agreed to in writing, software    -->
+<!-- distributed under the License is distributed on an "AS IS" BASIS,      -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        -->
+<!-- implied. License for the specific language governing permissions and   -->
+<!-- limitations under the License.                                         -->
+<html>
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+
+    <!--                                                               -->
+    <!-- Consider inlining CSS to reduce the number of requested files -->
+    <!--                                                               -->
+    <link type="text/css" rel="stylesheet" href="Validation.css">
+
+    <!--                                           -->
+    <!-- Any title is fine                         -->
+    <!--                                           -->
+    <title>javax.validation Starter Project</title>
+
+    <!--                                           -->
+    <!-- This script loads your compiled module.   -->
+    <!-- If you add any GWT meta tags, they must   -->
+    <!-- be added before this line.                -->
+    <!--                                           -->
+    <script type="text/javascript" language="javascript" src="validation/validation.nocache.js"></script>
+  </head>
+
+  <!--                                           -->
+  <!-- The body can have arbitrary html, or      -->
+  <!-- you can leave the body empty if you want  -->
+  <!-- to create a completely dynamic UI.        -->
+  <!--                                           -->
+  <body>
+
+    <!-- OPTIONAL: include this if you want history support -->
+    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
+
+    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
+    <noscript>
+      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
+        Your web browser must have JavaScript enabled
+        in order for this application to display correctly.
+      </div>
+    </noscript>
+
+    <h1>javax.validation Starter Project</h1>
+    <div id="view" />
+  </body>
+</html>
diff --git a/samples/validation/war/WEB-INF/web.xml b/samples/validation/war/WEB-INF/web.xml
new file mode 100644
index 0000000..9f79f03
--- /dev/null
+++ b/samples/validation/war/WEB-INF/web.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app>
+
+  <!-- Servlets -->
+  <servlet>
+    <servlet-name>greetServlet</servlet-name>
+    <servlet-class>com.google.gwt.sample.validation.server.GreetingServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>greetServlet</servlet-name>
+    <url-pattern>/validation/greet</url-pattern>
+  </servlet-mapping>
+
+  <!-- Default page to serve -->
+  <welcome-file-list>
+    <welcome-file>Validation.html</welcome-file>
+  </welcome-file-list>
+
+</web-app>
diff --git a/samples/validation/war/favicon.ico b/samples/validation/war/favicon.ico
new file mode 100644
index 0000000..25c8d88
--- /dev/null
+++ b/samples/validation/war/favicon.ico
Binary files differ