summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
commitaedc34d55462a75e329bbf342251ff6504cd117e (patch)
treebcc8f1f2352582717b484df302aeea6696b8f000 /projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java
Initial import from SVN
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java')
-rw-r--r--projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java
new file mode 100644
index 0000000..5d22d36
--- /dev/null
+++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOCheckBox.java
@@ -0,0 +1,81 @@
+
+package net.wotonomy.web;
+
+import net.wotonomy.foundation.NSArray;
+import net.wotonomy.foundation.NSDictionary;
+import net.wotonomy.foundation.NSMutableArray;
+
+public class WOCheckBox extends WOInput {
+
+ protected boolean checked = false;
+
+ public WOCheckBox() {
+ super();
+ }
+
+ public WOCheckBox(String aName, NSDictionary assocs, WOElement template) {
+ super(aName, assocs, template);
+ }
+
+ protected String inputType() {
+ return "CHECKBOX";
+ }
+
+ protected Object value(WOContext c) {
+ Object val = null;
+ boolean checked = false;
+ if (associations.objectForKey("value") != null) {
+ val = valueForProperty("value", c.component());
+ Object sel = valueForProperty("selection", c.component());
+ if (sel != null && val != null && sel.equals(val))
+ checked = true;
+ }
+ if (val == null) {
+ val = c.elementID();
+ }
+ return val;
+ }
+
+ protected void appendExtras(WOResponse r, WOContext c) {
+ checked |= booleanForProperty("checked", c.component());
+ if (checked)
+ r.appendContentString(" CHECKED");
+ }
+
+ protected NSMutableArray additionalAttributes() {
+ NSMutableArray a = super.additionalAttributes();
+ a.addObject("checked");
+ a.addObject("selection");
+ return a;
+ }
+
+ public void appendToResponse(WOResponse r, WOContext c) {
+ checked = false;
+ super.appendToResponse(r, c);
+ }
+
+ public void takeValuesFromRequest(WORequest r, WOContext c) {
+ if (disabled(c))
+ return;
+ NSArray values = r.formValuesForKey(inputName(c));
+ Object val = valueForProperty("value", c.component());
+ if (val == null)
+ val = c.elementID();
+ java.util.Enumeration enumerator = values.objectEnumerator();
+ checked = false;
+ while (enumerator.hasMoreElements()) {
+ Object nextval = enumerator.nextElement();
+ if (nextval.equals(val))
+ checked = true;
+ }
+ if (associations.objectForKey("value") != null && associations.objectForKey("selection") != null) {
+ if (checked)
+ setValueForProperty("selection", val, c.component());
+ else if (valueForProperty("selection", c.component()) != null)
+ setValueForProperty("selection", null, c.component());
+ }
+ if (associations.objectForKey("checked") != null)
+ setValueForProperty("checked", checked ? Boolean.TRUE : Boolean.FALSE, c.component());
+ }
+
+} \ No newline at end of file