click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1053753 - in /click/trunk/click/framework: src/org/apache/click/control/Select.java test/org/apache/click/control/SelectTest.java
Date Wed, 29 Dec 2010 21:55:35 GMT
Author: sabob
Date: Wed Dec 29 21:55:35 2010
New Revision: 1053753

URL: http://svn.apache.org/viewvc?rev=1053753&view=rev
Log:
ensure initial value is set when using DataProvider. CLK-745

Modified:
    click/trunk/click/framework/src/org/apache/click/control/Select.java
    click/trunk/click/framework/test/org/apache/click/control/SelectTest.java

Modified: click/trunk/click/framework/src/org/apache/click/control/Select.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Select.java?rev=1053753&r1=1053752&r2=1053753&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Select.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Select.java Wed Dec 29 21:55:35
2010
@@ -871,6 +871,9 @@ public class Select extends Field {
      */
     public void setOptionList(List options) {
         optionList = options;
+        if (optionList != null) {
+            setInitialValue();
+        }
     }
 
     /**

Modified: click/trunk/click/framework/test/org/apache/click/control/SelectTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/SelectTest.java?rev=1053753&r1=1053752&r2=1053753&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/SelectTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/SelectTest.java Wed Dec 29 21:55:35
2010
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.List;
 import junit.framework.TestCase;
 import org.apache.click.MockContext;
+import org.apache.click.dataprovider.DataProvider;
 
 /**
  * Test Select behavior.
@@ -149,4 +150,37 @@ public class SelectTest extends TestCase
         // restored
         select.getSelectedValues().add("male");
     }
+
+    /**
+     *
+     */
+    public void testSetInitialValue() {
+        // Setup Select
+        Select select  = new Select("gender");
+        select.add(new Option("male"));
+        select.add(new Option("female"));
+
+        String expectedValue = "male";
+
+        // Test initial value
+        assertEquals(expectedValue, select.getValue());
+        select.setValue(null);
+        select.setOptionList(null);
+
+        select.setDataProvider(new DataProvider() {
+
+            public List getData() {
+                List list = new ArrayList();
+                list.add(new Option("male"));
+                list.add(new Option("female"));
+                return list;
+            }
+        });
+
+        // Trigger dataProvider
+        select.getOptionList();
+
+        // Test initial value
+        assertEquals(expectedValue, select.getValue());
+    }
 }



Mime
View raw message