click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r933651 - in /click/trunk/click/examples/src/org/apache/click/examples/page: ajax/AjaxSelect.java control/SelectDemo.java form/StandardControlsForm.java form/dynamic/PopulateOnSelect.java introduction/AdvancedForm.java pageflow/StartPage.java
Date Tue, 13 Apr 2010 14:47:36 GMT
Author: sabob
Date: Tue Apr 13 14:47:36 2010
New Revision: 933651

URL: http://svn.apache.org/viewvc?rev=933651&view=rev
Log:
updated some selects to dataProvider

Modified:
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java
    click/trunk/click/examples/src/org/apache/click/examples/page/control/SelectDemo.java
    click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java
    click/trunk/click/examples/src/org/apache/click/examples/page/form/dynamic/PopulateOnSelect.java
    click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedForm.java
    click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java?rev=933651&r1=933650&r2=933651&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java Tue
Apr 13 14:47:36 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.examples.page.ajax;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import java.util.Map;
@@ -26,6 +27,7 @@ import javax.annotation.Resource;
 import org.apache.click.Context;
 import org.apache.click.control.Option;
 import org.apache.click.control.Select;
+import org.apache.click.dataprovider.DataProvider;
 import org.apache.click.element.Element;
 import org.apache.click.element.JsImport;
 import org.apache.click.element.JsScript;
@@ -55,12 +57,19 @@ public class AjaxSelect extends BorderPa
     public void onInit() {
         super.onInit();
 
-        List<Customer> customerList = customerService.getCustomersSortedByName(8);
-        for (Customer customer : customerList) {
-            customerSelect.add(new Option(customer.getId(), customer.getName()));
-        }
+        customerSelect.setSize(8);
+
+        customerSelect.setDataProvider(new DataProvider() {
 
-        customerSelect.setSize(customerList.size());
+            public List getData() {
+                List<Option> optionList = new ArrayList();
+                List<Customer> customerList = customerService.getCustomersSortedByName(8);
+                for (Customer customer : customerList) {
+                    optionList.add(new Option(customer.getId(), customer.getName()));
+                }
+                return optionList;
+            }
+        });
     }
 
     @Override

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/control/SelectDemo.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/control/SelectDemo.java?rev=933651&r1=933650&r2=933651&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/control/SelectDemo.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/control/SelectDemo.java
Tue Apr 13 14:47:36 2010
@@ -26,6 +26,7 @@ import org.apache.click.control.Option;
 import org.apache.click.control.OptionGroup;
 import org.apache.click.control.Select;
 import org.apache.click.control.Submit;
+import org.apache.click.dataprovider.DataProvider;
 import org.apache.click.examples.page.BorderPage;
 import org.apache.click.examples.page.HomePage;
 import org.apache.click.extras.control.CountrySelect;
@@ -52,15 +53,24 @@ public class SelectDemo extends BorderPa
     public SelectDemo() {
         form.setErrorsPosition(Form.POSITION_TOP);
 
-        // Gender Select
+        // Gender Select - populated through a DataProvider
         genderSelect = new Select("gender");
         genderSelect.setRequired(true);
-        genderSelect.add(new Option("U", ""));
-        genderSelect.add(new Option("M", "Male"));
-        genderSelect.add(new Option("F", "Female"));
+
+        genderSelect.setDefaultOption(new Option("U", ""));
+        genderSelect.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List optionList = new ArrayList(3);
+                optionList.add(new Option("M", "Male"));
+                optionList.add(new Option("F", "Female"));
+                return optionList;
+            }
+        });
+
         form.add(genderSelect);
 
-        // Investment Select
+        // Investment Select - populated through Select.add methods
         List investmentOptions = new ArrayList();
 
         OptionGroup property = new OptionGroup("property");

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java?rev=933651&r1=933650&r2=933651&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java
Tue Apr 13 14:47:36 2010
@@ -134,7 +134,7 @@ public class StandardControlsForm extend
 
         // Create dataprovider for Select
         DataProvider dp = new DataProvider() {
-            public Iterable getData() {
+            public List getData() {
                 return createOptionList(customerService.getCustomers());
             }
         };

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=933651&r1=933650&r2=933651&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
Tue Apr 13 14:47:36 2010
@@ -18,13 +18,16 @@
  */
 package org.apache.click.examples.page.form.dynamic;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.click.control.FieldSet;
+import org.apache.click.control.Option;
 import org.apache.click.control.Select;
 import org.apache.click.control.Submit;
+import org.apache.click.dataprovider.DataProvider;
 import org.apache.click.element.Element;
 import org.apache.click.element.JsScript;
 import org.apache.click.examples.page.BorderPage;
@@ -85,9 +88,9 @@ public class PopulateOnSelect extends Bo
     // Public Methods ---------------------------------------------------------
 
     public void buildSelects() {
-        state.add("---");
-        city.add("---");
-        suburb.add("---");
+        state.setDefaultOption(new Option("---"));
+        city.setDefaultOption(new Option("---"));
+        suburb.setDefaultOption(new Option("---"));
 
         // Populate the States. Do this before binding requests
         populateStateData();
@@ -134,52 +137,87 @@ public class PopulateOnSelect extends Bo
 
     @SuppressWarnings("serial")
     private void populateStateData() {
-        Map<String, String> map = new HashMap<String, String>() {{
-                put(EASTERN_CAPE, "Eastern Cape");
-                put(FREE_STATE, "Free State");
-                put(GAUTENG_PROVINCE, "Gauteng Province");
-                put(WESTERN_CAPE, "Western Cape");
-            }};
-        state.addAll(map);
-    }
-
-    private void populateCityData(String stateCode) {
-        String[] cities = null;
-        if (EASTERN_CAPE.equals(stateCode)) {
-            cities = new String[] {"Port Elizabeth", "East London"};
-        } else if (FREE_STATE.equals(stateCode)) {
-            cities = new String[] {"Bloemfontein", "Welkom"};
-        } else if (GAUTENG_PROVINCE.equals(stateCode)) {
-            cities = new String[] {"Johannesburg", "Pretoria"};
-        } else if (WESTERN_CAPE.equals(stateCode)) {
-            cities = new String[] {"Cape Town", "George"};
-        }
-        if (cities != null) {
-            city.addAll(cities);
-        }
-    }
+        state.setDataProvider(new DataProvider() {
 
-    private void populateSuburbData(String cityCode) {
-        String[] suburbs = null;
-        if (cityCode.equals("Port Elizabeth")) {
-            suburbs = new String[] {"Humewood", "Summerstrand"};
-        } else if (cityCode.equals("East London")) {
-            suburbs = new String[] {"Beacon Bay", "Cinta East"};
-        } else if (cityCode.equals("Bloemfontein")) {
-            suburbs = new String[] {"Fichardpark", "Wilgehof"};
-        } else if (cityCode.equals("Welkom")) {
-            suburbs = new String[] {"Dagbreek", "Eerstemyn"};
-        } else if (cityCode.equals("Johannesburg")) {
-            suburbs = new String[] {"Rivonia", "Sandton"};
-        } else if (cityCode.equals("Pretoria")) {
-            suburbs = new String[] {"Garsfontein", "Sunnyside"};
-        } else if (cityCode.equals("Cape Town")) {
-            suburbs = new String[] {"Milnerton", "Blaauwberg"};
-        } else if (cityCode.equals("George")) {
-            suburbs = new String[] {"Panorama", "Fernridge"};
-        }
-        if (suburbs != null) {
-            suburb.addAll(suburbs);
-        }
+            public List getData() {
+                List optionList = new ArrayList();
+                optionList.add(new Option(EASTERN_CAPE, "Eastern Cape"));
+                optionList.add(new Option(FREE_STATE, "Free State"));
+                optionList.add(new Option(GAUTENG_PROVINCE, "Gauteng Province"));
+                optionList.add(new Option(WESTERN_CAPE, "Western Cape"));
+                return optionList;
+            }
+        });
+    }
+
+    private void populateCityData(final String stateCode) {
+        city.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List optionList = new ArrayList();
+
+                if (EASTERN_CAPE.equals(stateCode)) {
+                    optionList.add(new Option("Port Elizabeth"));
+                    optionList.add(new Option("East London"));
+
+                } else if (FREE_STATE.equals(stateCode)) {
+                    optionList.add(new Option("Bloemfontein"));
+                    optionList.add(new Option("Welkom"));
+
+                } else if (GAUTENG_PROVINCE.equals(stateCode)) {
+                    optionList.add(new Option("Johannesburg"));
+                    optionList.add(new Option("Pretoria"));
+
+                } else if (WESTERN_CAPE.equals(stateCode)) {
+                    optionList.add(new Option("Cape Town"));
+                    optionList.add(new Option("George"));
+                }
+                return optionList;
+            }
+        });
+    }
+
+    private void populateSuburbData(final String cityCode) {
+        suburb.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List optionList = new ArrayList();
+
+                if (cityCode.equals("Port Elizabeth")) {
+                    optionList.add(new Option("Humewood"));
+                    optionList.add(new Option("Summerstrand"));
+
+                } else if (cityCode.equals("East London")) {
+                    optionList.add(new Option("Beacon Bay"));
+                    optionList.add(new Option("Cinta East"));
+
+                } else if (cityCode.equals("Bloemfontein")) {
+                    optionList.add(new Option("Fichardpark"));
+                    optionList.add(new Option("Wilgehof"));
+
+                } else if (cityCode.equals("Welkom")) {
+                    optionList.add(new Option("Dagbreek"));
+                    optionList.add(new Option("Eerstemyn"));
+
+                } else if (cityCode.equals("Johannesburg")) {
+                    optionList.add(new Option("Rivonia"));
+                    optionList.add(new Option("Sandton"));
+
+                } else if (cityCode.equals("Pretoria")) {
+                    optionList.add(new Option("Garsfontein"));
+                    optionList.add(new Option("Sunnyside"));
+
+                } else if (cityCode.equals("Cape Town")) {
+                    optionList.add(new Option("Milnerton"));
+                    optionList.add(new Option("Blaauwberg"));
+
+                } else if (cityCode.equals("George")) {
+                    optionList.add(new Option("Panorama"));
+                    optionList.add(new Option("Fernridge"));
+                }
+
+                return optionList;
+            }
+        });
     }
 }

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedForm.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedForm.java?rev=933651&r1=933650&r2=933651&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedForm.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/introduction/AdvancedForm.java
Tue Apr 13 14:47:36 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.examples.page.introduction;
 
+import java.util.List;
 import javax.annotation.Resource;
 
 import org.apache.click.Page;
@@ -28,6 +29,7 @@ import org.apache.click.control.Option;
 import org.apache.click.control.Select;
 import org.apache.click.control.Submit;
 import org.apache.click.control.TextField;
+import org.apache.click.dataprovider.DataProvider;
 import org.apache.click.examples.domain.Customer;
 import org.apache.click.examples.page.BorderPage;
 import org.apache.click.examples.page.HomePage;
@@ -84,8 +86,14 @@ public class AdvancedForm extends Border
     public void onInit() {
         super.onInit();
 
-        investmentSelect.add(Option.EMPTY_OPTION);
-        investmentSelect.addAll(customerService.getInvestmentCatetories());
+        investmentSelect.setDefaultOption(Option.EMPTY_OPTION);
+        investmentSelect.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List categories = customerService.getInvestmentCatetories();
+                return categories;
+            }
+        });
     }
 
     /**

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java?rev=933651&r1=933650&r2=933651&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java
Tue Apr 13 14:47:36 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.examples.page.pageflow;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -29,6 +30,7 @@ import org.apache.click.control.Option;
 import org.apache.click.control.Select;
 import org.apache.click.control.Submit;
 import org.apache.click.control.TextArea;
+import org.apache.click.dataprovider.DataProvider;
 import org.apache.click.element.Element;
 import org.apache.click.element.JsImport;
 import org.apache.click.element.JsScript;
@@ -73,6 +75,20 @@ public class StartPage extends BorderPag
         customerSelect.setRequired(true);
         form.add(customerSelect);
 
+        customerSelect.setDefaultOption(Option.EMPTY_OPTION);
+        customerSelect.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List optionList = new ArrayList();
+                List<Customer> customerList = customerService.getCustomers();
+                for (Customer customer : customerList) {
+                    optionList.add(new Option(customer.getId(),
+                                                  customer.getName()));
+                }
+                return optionList;
+            }
+        });
+
         dateField = new DateField("Booking Date");
         dateField.setRequired(true);
         form.add(dateField);
@@ -106,12 +122,6 @@ public class StartPage extends BorderPag
     public void onInit() {
         super.onInit();
 
-        List<Customer> customerList = customerService.getCustomers();
-        customerSelect.add(Option.EMPTY_OPTION);
-        for (Customer customer : customerList) {
-            customerSelect.add(new Option(customer.getId(), customer.getName()));
-        }
-
         if (getContext().isForward() && courseBooking != null) {
             customerSelect.setValueObject(courseBooking.getCustomerId());
             dateField.setDate(courseBooking.getBookingDate());



Mime
View raw message