click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1036804 - in /click/trunk/click/examples: src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java webapp/form/dynamic/populate-on-select.js
Date Fri, 19 Nov 2010 11:08:56 GMT
Author: sabob
Date: Fri Nov 19 11:08:55 2010
New Revision: 1036804

URL: http://svn.apache.org/viewvc?rev=1036804&view=rev
Log:
convert bypass validation examples

Modified:
    click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java
    click/trunk/click/examples/webapp/form/dynamic/populate-on-select.js

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java?rev=1036804&r1=1036803&r2=1036804&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java
Fri Nov 19 11:08:55 2010
@@ -37,7 +37,7 @@ import org.apache.click.util.ClickUtils;
 import org.apache.commons.lang.StringUtils;
 
 /**
- * Demonstrate how to populate Select controls.
+ * Demonstrate how to dynamically populate Select controls.
  */
 public class PopulateOnSelect extends BorderPage {
 
@@ -79,18 +79,18 @@ public class PopulateOnSelect extends Bo
         fieldSet.add(city);
         fieldSet.add(suburb);
 
+        form.add(save);
+
         // build the Selects in the onInit phase
         buildSelects();
-
-        form.add(save);
     }
 
     // Public Methods ---------------------------------------------------------
 
     public void buildSelects() {
-        state.setDefaultOption(new Option("---"));
-        city.setDefaultOption(new Option("---"));
-        suburb.setDefaultOption(new Option("---"));
+        state.setDefaultOption(Option.EMPTY_OPTION);
+        city.setDefaultOption(Option.EMPTY_OPTION);
+        suburb.setDefaultOption(Option.EMPTY_OPTION);
 
         // Populate the States. Do this before binding requests
         populateStateData();
@@ -113,6 +113,11 @@ public class PopulateOnSelect extends Bo
 
         // If city is selected, proceed to populate suburbs
         populateSuburbData(city.getValue());
+
+        // If save was not clicked, don't validate
+        if(form.isFormSubmission() && !save.isClicked()) {
+            form.setValidate(false);
+        }
     }
 
     @Override
@@ -120,14 +125,14 @@ public class PopulateOnSelect extends Bo
         if (headElements == null) {
             headElements = super.getHeadElements();
 
-            Map<String, Object> model = new HashMap<String, Object>();
-            model.put("stateId", state.getId());
-            model.put("cityId", city.getId());
-            model.put("suburbId", suburb.getId());
+            Map<String, Object> templateModel = new HashMap<String, Object>();
+            templateModel.put("stateId", state.getId());
+            templateModel.put("cityId", city.getId());
+            templateModel.put("suburbId", suburb.getId());
 
             // populate-on-select.js is a Velocity template which is rendered directly
             // from this Page
-            JsScript script = new JsScript("/form/dynamic/populate-on-select.js", model);
+            JsScript script = new JsScript("/form/dynamic/populate-on-select.js", templateModel);
             headElements.add(script);
         }
         return headElements;

Modified: click/trunk/click/examples/webapp/form/dynamic/populate-on-select.js
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/form/dynamic/populate-on-select.js?rev=1036804&r1=1036803&r2=1036804&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/form/dynamic/populate-on-select.js (original)
+++ click/trunk/click/examples/webapp/form/dynamic/populate-on-select.js Fri Nov 19 11:08:55
2010
@@ -28,7 +28,7 @@ function printValues() {
     var state = document.getElementById('${stateId}');
     var city = document.getElementById('${cityId}');
     var suburb = document.getElementById('${suburbId}');
-    
+
     var html = 'Selected state: key -> ' + state.value + ', value -> ' + state.options[state.selectedIndex].text;
     html+="<br>" + 'Selected city: key -> ' + city.value  + ', value -> ' + city.options[city.selectedIndex].text;
     html+="<br>" + 'Selected suburb: key -> ' + suburb.value  + ', value -> '
+ suburb.options[suburb.selectedIndex].text;
@@ -47,6 +47,6 @@ function handleChange(id, form) {
         // Clear dependent Select value
         select.selectedIndex=0;
     }
-    // Submit form and bypass server-side validation
-    Click.submit(form, false);
+    // Submit form
+    form.submit();
 }
\ No newline at end of file



Mime
View raw message