click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r931073 - /click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java
Date Tue, 06 Apr 2010 10:03:33 GMT
Author: sabob
Date: Tue Apr  6 10:03:33 2010
New Revision: 931073

URL: http://svn.apache.org/viewvc?rev=931073&view=rev
Log:
provide a dataprovider for Select

Modified:
    click/trunk/click/examples/src/org/apache/click/examples/page/form/StandardControlsForm.java

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=931073&r1=931072&r2=931073&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  6 10:03:33 2010
@@ -19,6 +19,7 @@
 package org.apache.click.examples.page.form;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.annotation.Resource;
@@ -47,6 +48,7 @@ import org.apache.click.examples.service
 import org.apache.click.examples.util.ExampleUtils;
 import org.apache.click.util.Bindable;
 import org.apache.click.util.ContainerUtils;
+import org.apache.click.dataprovider.DataProvider;
 import org.springframework.stereotype.Component;
 
 /**
@@ -127,9 +129,17 @@ public class StandardControlsForm extend
     public void onInit() {
         super.onInit();
 
-        List<Customer> customers = customerService.getCustomers();
-        select.add(new Option("[Select]"));
-        select.addAll(customers, "id", "name");
+        // Set default non-selecting option
+        select.setDefaultOption(new Option("[Select]"));
+
+        // Create dataprovider for Select
+        DataProvider dp = new DataProvider() {
+            public Iterable getData() {
+                return createOptionList(customerService.getCustomers());
+            }
+        };
+        select.setDataProvider(dp);
+
         applyOptions();
     }
 
@@ -144,6 +154,14 @@ public class StandardControlsForm extend
 
     // Private Methods --------------------------------------------------------
 
+    private List createOptionList(List<Customer> customers) {
+        List optionList = new ArrayList();
+        for (Customer customer : customers) {
+            optionList.add(new Option(customer.getId(), customer.getName()));
+        }
+        return optionList;
+    }
+
     private void applyOptions() {
         Options options = (Options) ExampleUtils.getSessionObject(Options.class);
 



Mime
View raw message