Added the maximum length property to text boxes.
authorMarco Zanon <info@marcozanon.com>
Sun, 11 Mar 2012 13:50:35 +0000 (13:50 +0000)
committerMarco Zanon <info@marcozanon.com>
Sun, 11 Mar 2012 13:50:35 +0000 (13:50 +0000)
src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java
src/java/com/marcozanon/macaco/web/ui/MWebExtendedTextBox.java
src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java
src/java/com/marcozanon/macaco/web/ui/MWebPasswordBox.java
src/java/com/marcozanon/macaco/web/ui/MWebSimpleTextBox.java
src/java/com/marcozanon/macaco/web/ui/MWebTextBox.java

index 803143477d2d7a062cfafe726b9bc290f0f83278..fc89489a6e8f187516c5f60d2553114f068c4959 100644 (file)
@@ -72,6 +72,7 @@ public class MWebDateBox extends MWebTextBox {
         //
         this.refreshText();
         this.refreshTextAlignment(true);
+        this.refreshMaximumLength();
         this.refreshEnabledMode();
     }
 
index 69af9ba71ab86cb12cbab924f283e1d86b78b7a8..4ef73a363fc2d34c326307dce958c157a07113ff 100644 (file)
@@ -38,6 +38,7 @@ public class MWebExtendedTextBox extends MWebTextBox {
         //
         this.refreshText();
         this.refreshTextAlignment(true);
+        this.refreshMaximumLength();
         this.refreshEnabledMode();
     }
 
index 55062e91658cd3270434eea9758c1f4c83033d09..f8ccf26a2a1c696c83015abaa656af3eb1dd774b 100644 (file)
@@ -72,6 +72,7 @@ public class MWebNumberBox extends MWebTextBox {
         //
         this.refreshText();
         this.refreshTextAlignment(true);
+        this.refreshMaximumLength();
         this.refreshEnabledMode();
     }
 
index 8b685a3d21130396d19a7dc6f2467393822c093e..28401b17186ca071b3033c2bc3a8fb8151a06108 100644 (file)
@@ -36,6 +36,7 @@ public class MWebPasswordBox extends MWebTextBox {
         //
         this.refreshText();
         this.refreshTextAlignment(true);
+        this.refreshMaximumLength();
         this.refreshEnabledMode();
     }
 
index 5bd1e001ab87dcc2c6cbe17fc7d62079b94520b9..630a07e5180f58a67eadfdbb25f40b46a571a20f 100644 (file)
@@ -36,6 +36,7 @@ public class MWebSimpleTextBox extends MWebTextBox {
         //
         this.refreshText();
         this.refreshTextAlignment(true);
+        this.refreshMaximumLength();
         this.refreshEnabledMode();
     }
 
index 273538b95e716605105285134aa9e29e90fc8393..9bbf4313f78f217f0ea870fbc5868600a6455f6a 100644 (file)
@@ -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();
         //