From 20f0cd333d4d8bb5eddcff2c1dad47ead4ee7bb8 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Sun, 11 Mar 2012 13:50:35 +0000 Subject: [PATCH] Added the maximum length property to text boxes. --- .../marcozanon/macaco/web/ui/MWebDateBox.java | 1 + .../macaco/web/ui/MWebExtendedTextBox.java | 1 + .../macaco/web/ui/MWebNumberBox.java | 1 + .../macaco/web/ui/MWebPasswordBox.java | 1 + .../macaco/web/ui/MWebSimpleTextBox.java | 1 + .../marcozanon/macaco/web/ui/MWebTextBox.java | 51 +++++++++++++++++++ 6 files changed, 56 insertions(+) diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java index 8031434..fc89489 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java @@ -72,6 +72,7 @@ public class MWebDateBox extends MWebTextBox { // this.refreshText(); this.refreshTextAlignment(true); + this.refreshMaximumLength(); this.refreshEnabledMode(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java index 69af9ba..4ef73a3 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java @@ -38,6 +38,7 @@ public class MWebExtendedTextBox extends MWebTextBox { // this.refreshText(); this.refreshTextAlignment(true); + this.refreshMaximumLength(); this.refreshEnabledMode(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java index 55062e9..f8ccf26 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java @@ -72,6 +72,7 @@ public class MWebNumberBox extends MWebTextBox { // this.refreshText(); this.refreshTextAlignment(true); + this.refreshMaximumLength(); this.refreshEnabledMode(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java index 8b685a3..28401b1 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java @@ -36,6 +36,7 @@ public class MWebPasswordBox extends MWebTextBox { // this.refreshText(); this.refreshTextAlignment(true); + this.refreshMaximumLength(); this.refreshEnabledMode(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java index 5bd1e00..630a07e 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java @@ -36,6 +36,7 @@ public class MWebSimpleTextBox extends MWebTextBox { // this.refreshText(); this.refreshTextAlignment(true); + this.refreshMaximumLength(); this.refreshEnabledMode(); } diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java index 273538b..9bbf431 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java @@ -25,6 +25,7 @@ public abstract class MWebTextBox extends MWebDirectWidget { protected String text = ""; protected MWebTextBox.TextAlignment textAlignment = null; + protected Integer maximumLength = null; protected boolean enabledMode = true; @@ -117,6 +118,45 @@ public abstract class MWebTextBox extends MWebDirectWidget { return this.getTextAlignment().toString(); } + /* Maximum length */ + + public void setMaximumLength(Integer maximumLength) { + this.setMaximumLength(maximumLength, true); + } + + protected void setMaximumLength(Integer maximumLength, boolean refreshMode) { + if ((null != maximumLength) && (0 > maximumLength)) { + throw new IllegalArgumentException("Invalid 'maximumLength': negative number."); + } + // + this.maximumLength = maximumLength; + // + if (refreshMode) { + try { + this.refreshMaximumLength(); + } + catch (MNoBrowserPageWebException exception) { + } + catch (MNoViewWebException exception) { + } + catch (MNoWidgetIdWebException exception) { + } + catch (MResponseWebException exception) { + } + } + } + + public Integer getMaximumLength() { + return this.maximumLength; + } + + public String getFormattedMaximumLength() throws MNullPropertyWebException { + if (null == this.getMaximumLength()) { + throw new MNullPropertyWebException("Invalid maximum length: property null."); + } + return this.getMaximumLength().toString(); + } + /* Enabled mode */ public void setEnabledMode(boolean enabledMode) { @@ -172,6 +212,17 @@ public abstract class MWebTextBox extends MWebDirectWidget { } } + protected void refreshMaximumLength() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException { + this.checkPresence(); + // + try { + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').maxLength = '%s'; }", this.getId(), this.getId(), this.getFormattedMaximumLength())); + } + catch (MNullPropertyWebException exception) { + this.getApplicationContextReference().addPlainTextResponseContent(String.format("if ($('%s')) { $('%s').maxLength = null; }", this.getId(), this.getId())); + } + } + protected void refreshEnabledMode() throws MNoBrowserPageWebException, MNoViewWebException, MNoWidgetIdWebException, MResponseWebException { this.checkPresence(); // -- 2.30.2