click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1030960 - in /click/trunk/click/extras: src/org/apache/click/extras/control/PickList.java test/org/apache/click/extras/control/PickListTest.java
Date Thu, 04 Nov 2010 13:33:00 GMT
Author: sabob
Date: Thu Nov  4 13:33:00 2010
New Revision: 1030960

URL: http://svn.apache.org/viewvc?rev=1030960&view=rev
Log:
added stateful PickList. CLK-715

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/PickList.java
    click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/PickList.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/PickList.java?rev=1030960&r1=1030959&r2=1030960&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/PickList.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/PickList.java Thu Nov  4
13:33:00 2010
@@ -788,6 +788,43 @@ public class PickList extends Field {
     }
 
     /**
+     * Return the PickList state. The following state is returned:
+     * <ul>
+     * <li>{@link #getSelectedValues()}</li>
+     * </ul>
+     *
+     * @return the PickList state
+     */
+    @Override
+    public Object getState() {
+            List selectedState = getSelectedValues();
+        if (selectedState.isEmpty()) {
+            return null;
+        } else {
+            return selectedState.toArray(new String[0]);
+        }
+    }
+
+    /**
+     * Set the PickList state.
+     *
+     * @param state the PickList state to set
+     */
+    @Override
+    public void setState(Object state) {
+        if (state == null) {
+            return;
+        }
+
+        String[] pickListState = (String[]) state;
+        List<String> localSelectedState = new ArrayList<String>(pickListState.length);
+        for (String val : pickListState) {
+            localSelectedState.add(val);
+        }
+        setSelectedValues(localSelectedState);
+    }
+
+    /**
      * Validate the PickList request submission.
      * <p/>
      * A field error message is displayed if a validation error occurs.

Modified: click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java?rev=1030960&r1=1030959&r2=1030960&view=diff
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java (original)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/PickListTest.java Thu Nov
 4 13:33:00 2010
@@ -131,5 +131,9 @@ public class PickListTest extends TestCa
         assertEquals("", pickList.getValue()); // PickList use value but selectedValues instead
         assertTrue(Arrays.equals(expectedState, pickList.getSelectedValues().toArray()));
         assertEquals(pickList.getSelectedValues(), (pickList.getValueObject()));
+
+        // Make sure we can still add values to the PickList after state is
+        // restored
+        pickList.addSelectedValue("004");
     }
 }



Mime
View raw message