You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/06/29 23:10:38 UTC

svn commit: r789448 - in /incubator/click/trunk/click/examples: src/org/apache/click/examples/page/form/SearchForm.java webapp/form/search-form.htm

Author: sabob
Date: Mon Jun 29 21:10:37 2009
New Revision: 789448

URL: http://svn.apache.org/viewvc?rev=789448&view=rev
Log:
validate ID number

Modified:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/form/SearchForm.java
    incubator/click/trunk/click/examples/webapp/form/search-form.htm

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/form/SearchForm.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/form/SearchForm.java?rev=789448&r1=789447&r2=789448&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/form/SearchForm.java (original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/form/SearchForm.java Mon Jun 29 21:10:37 2009
@@ -30,6 +30,8 @@
 import org.apache.click.examples.page.BorderPage;
 import org.apache.click.examples.service.CustomerService;
 import org.apache.click.util.Bindable;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.springframework.stereotype.Component;
 
 /**
@@ -72,7 +74,11 @@
         String type = typeSelect.getValue().toLowerCase();
 
         if (type.equals("id")) {
-            customer = customerService.findCustomerByID(value);
+            if (NumberUtils.isDigits(value)) {
+                customer = customerService.findCustomerByID(value);
+            } else {
+                textField.setError("ID must be a number");
+            }
         }
         else if (type.equals("name")) {
             List<Customer> list = customerService.getCustomersForName(value);

Modified: incubator/click/trunk/click/examples/webapp/form/search-form.htm
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/form/search-form.htm?rev=789448&r1=789447&r2=789448&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/webapp/form/search-form.htm (original)
+++ incubator/click/trunk/click/examples/webapp/form/search-form.htm Mon Jun 29 21:10:37 2009
@@ -21,6 +21,12 @@
 <p>
 
 $form.startTag()
+
+<!-- Show validation errors -->
+#if (!$form.fields.search.valid)
+<div style="color: red;margin-bottom: 1em"> $form.fields.search.error</div>
+#end
+
  <b>Customer</b> ${form.fields.search}${form.fields.type}${form.fields.go}
 $form.endTag()