You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/11/17 09:50:16 UTC
svn commit: r1035952 - in /click/trunk/click/extras:
src/org/apache/click/extras/control/CheckList.java
test/org/apache/click/extras/control/CheckListTest.java
Author: sabob
Date: Wed Nov 17 08:50:16 2010
New Revision: 1035952
URL: http://svn.apache.org/viewvc?rev=1035952&view=rev
Log:
Fix requird checklist validation
Modified:
click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java
click/trunk/click/extras/test/org/apache/click/extras/control/CheckListTest.java
Modified: click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java?rev=1035952&r1=1035951&r2=1035952&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/CheckList.java Wed Nov 17 08:50:16 2010
@@ -953,6 +953,40 @@ public class CheckList extends Field {
}
/**
+ * Process the request Context setting the CheckList selectedValues if
+ * selected and invoking the control's listener if defined.
+ *
+ * @return true to continue Page event processing, false otherwise
+ */
+ @Override
+ public boolean onProcess() {
+ if (isDisabled()) {
+ Context context = getContext();
+
+ // Switch off disabled property if control has incoming request
+ // parameter. Normally this means the field was enabled via JS
+ if (context.hasRequestParameter(getName())) {
+ setDisabled(false);
+ } else {
+ // If field is disabled skip process event
+ return true;
+ }
+ }
+
+ // In Html an unchecked CheckList does not submit it's name/value so we
+ // always validate and dispatch registered events
+ bindRequestValue();
+
+ if (getValidate()) {
+ validate();
+ }
+
+ dispatchActionEvent();
+
+ return true;
+ }
+
+ /**
* Sorts the current Options List. This method is called
* in {@link #bindRequestValue()} when the CheckList
* is sortable.
Modified: click/trunk/click/extras/test/org/apache/click/extras/control/CheckListTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/test/org/apache/click/extras/control/CheckListTest.java?rev=1035952&r1=1035951&r2=1035952&view=diff
==============================================================================
--- click/trunk/click/extras/test/org/apache/click/extras/control/CheckListTest.java (original)
+++ click/trunk/click/extras/test/org/apache/click/extras/control/CheckListTest.java Wed Nov 17 08:50:16 2010
@@ -113,4 +113,41 @@ public class CheckListTest extends TestC
// Check that the value <script> is not rendered
assertTrue(checkList.toString().indexOf(value) < 0);
}
+
+ /**
+ * Check that required CheckList is invalid if not filled in.
+ *
+ * CLK-722
+ */
+ public void testRequiredInvalid() {
+ MockContext.initContext();
+ CheckList cl = new CheckList("cl");
+ cl.setRequired(true);
+ int[] in = {1,2,3,4,5,6};
+ List<Option> ol = createOptionsList(in);
+ cl.setOptionList(ol);
+ cl.onProcess();
+
+ // Perform test
+ assertFalse(cl.isValid());
+ }
+
+ /**
+ * Check that required CheckList is valid if at least one checkbox is checked.
+ *
+ * CLK-722
+ */
+ public void testRequiredValid() {
+ MockContext context = MockContext.initContext();
+ context.getMockRequest().setParameter("cl", "1");
+ CheckList cl = new CheckList("cl");
+ cl.setRequired(true);
+ int[] in = {1,2,3,4,5,6};
+ List<Option> ol = createOptionsList(in);
+ cl.setOptionList(ol);
+ cl.onProcess();
+
+ // Perform test
+ assertTrue(cl.isValid());
+ }
}