diff options
Diffstat (limited to 'projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java')
| -rw-r--r-- | projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java | 135 |
1 files changed, 68 insertions, 67 deletions
diff --git a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java index a8c7daa..ddcdb9e 100644 --- a/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java +++ b/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOInput.java @@ -10,74 +10,75 @@ import net.wotonomy.foundation.NSMutableArray; public abstract class WOInput extends WODynamicElement { - public WOInput() { - super(); - } - - public WOInput(String aName, NSDictionary assocs, WOElement template) { - super(aName, assocs, template); - } - - protected abstract String inputType(); - protected abstract Object value(WOContext c); - - protected NSMutableArray additionalAttributes() { - return new NSMutableArray(new Object[]{ - "disabled", "type", "value", "name" - }); - } - - public String inputName(WOContext c) { - String x = (String)valueForProperty("name", c.component()); - if (x != null) - return x; - return c.elementID(); - } - - protected boolean disabled(WOContext c) { - return booleanForProperty("disabled", c.component()); - } - - protected void appendExtras(WOResponse r, WOContext c) { - } - - public void appendToResponse(WOResponse r, WOContext c) { - r.appendContentString("<INPUT TYPE=\""); - r.appendContentString(inputType()); - r.appendContentString("\" NAME=\""); - r.appendContentString(inputName(c)); - r.appendContentString("\" VALUE=\""); - r.appendContentString(value(c).toString()); - r.appendContentString("\""); - String moreFields = additionalHTMLProperties(c.component(), additionalAttributes()); - if (moreFields != null && moreFields.length() > 0) - r.appendContentString(moreFields); - appendExtras(r, c); - if (disabled(c)) { - r.appendContentString(" DISABLED"); - } - r.appendContentString(">"); - } - - public void takeValuesFromRequest(WORequest r, WOContext c) { - if (disabled(c)) - return; - Object val = r.formValueForKey(inputName(c)); - WOAssociation va = (WOAssociation)associations.objectForKey("value"); - if (val != null && va != null && va.isValueSettable()) - setValueForProperty("value", val, c.component()); - } - - /** Formats a value as a date or number. Checks for - * numberformat or dateformat associations; if one of them - * exists, the value is formatter using the specified pattern. + public WOInput() { + super(); + } + + public WOInput(String aName, NSDictionary assocs, WOElement template) { + super(aName, assocs, template); + } + + protected abstract String inputType(); + + protected abstract Object value(WOContext c); + + protected NSMutableArray additionalAttributes() { + return new NSMutableArray(new Object[] { "disabled", "type", "value", "name" }); + } + + public String inputName(WOContext c) { + String x = (String) valueForProperty("name", c.component()); + if (x != null) + return x; + return c.elementID(); + } + + protected boolean disabled(WOContext c) { + return booleanForProperty("disabled", c.component()); + } + + protected void appendExtras(WOResponse r, WOContext c) { + } + + public void appendToResponse(WOResponse r, WOContext c) { + r.appendContentString("<INPUT TYPE=\""); + r.appendContentString(inputType()); + r.appendContentString("\" NAME=\""); + r.appendContentString(inputName(c)); + r.appendContentString("\" VALUE=\""); + r.appendContentString(value(c).toString()); + r.appendContentString("\""); + String moreFields = additionalHTMLProperties(c.component(), additionalAttributes()); + if (moreFields != null && moreFields.length() > 0) + r.appendContentString(moreFields); + appendExtras(r, c); + if (disabled(c)) { + r.appendContentString(" DISABLED"); + } + r.appendContentString(">"); + } + + public void takeValuesFromRequest(WORequest r, WOContext c) { + if (disabled(c)) + return; + Object val = r.formValueForKey(inputName(c)); + WOAssociation va = (WOAssociation) associations.objectForKey("value"); + if (val != null && va != null && va.isValueSettable()) + setValueForProperty("value", val, c.component()); + } + + /** + * Formats a value as a date or number. Checks for numberformat or dateformat + * associations; if one of them exists, the value is formatter using the + * specified pattern. + * * @param value The value to format. - * @return The original object, or a date or number if the - * receiver has a numberformat or dateformat association. + * @return The original object, or a date or number if the receiver has a + * numberformat or dateformat association. */ protected Object formattedValue(Object value, WOComponent c) { - //Format the value in case of number - String pattern = (String)valueForProperty("numberformat", c); + // Format the value in case of number + String pattern = (String) valueForProperty("numberformat", c); if (pattern != null) { DecimalFormat fmt = new DecimalFormat(pattern); try { @@ -86,8 +87,8 @@ public abstract class WOInput extends WODynamicElement { return value; } } - //Format the value in case of date - pattern = (String)valueForProperty("dateformat", c); + // Format the value in case of date + pattern = (String) valueForProperty("dateformat", c); if (pattern != null) { SimpleDateFormat fmt = new SimpleDateFormat(pattern); try { |
