CLK-794

git-svn-id: https://svn.apache.org/repos/asf/click/trunk/click@1389369 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/org/apache/click/control/TextField.java b/framework/src/org/apache/click/control/TextField.java
index f7a4306..53b3d8b 100644
--- a/framework/src/org/apache/click/control/TextField.java
+++ b/framework/src/org/apache/click/control/TextField.java
@@ -103,6 +103,9 @@
      */
     protected int minLength = 0;
 
+    /** The field HTML5 placeholder attribute. */
+    protected String placeholder;
+
     /** The text field size attribute. The default size is 20. */
     protected int size = 20;
 
@@ -189,7 +192,34 @@
     public TextField() {
     }
 
-    // ------------------------------------------------------ Public Attributes
+    // Public Attributes ------------------------------------------------------
+
+    /**
+     * Return true if input field HTML5 autocomplete enabled.
+     *
+     * @return true if input field HTML5 autocomplete enabled.
+     */
+    public boolean isAutocomplete() {
+        String value = getAttribute("autocomplete");
+        if (value != null) {
+            return "on".equals(value);
+        } else {
+            return true;
+        }
+    }
+
+    /**
+     * Set the input field HTML5 autocomplete status.
+     *
+     * @return true if input field HTML5 autocomplete enabled.
+     */
+    public void setAutocomplete(boolean autocomplete) {
+        if (autocomplete) {
+            setAttribute("autocomplete", "on");
+        } else{
+            setAttribute("autocomplete", "off");
+        }
+    }
 
     /**
      * Return the textfield's html tag: <tt>input</tt>.
@@ -254,6 +284,36 @@
     }
 
     /**
+     * Return the input field HTML5 placeholder attribute.
+     * <p/>
+     * If the placeholder value is null, this method will attempt to find a
+     * localized placeholder message in the parent messages using the key:
+     * <blockquote>
+     * <tt>getName() + ".placeholder"</tt>
+     * </blockquote>
+     * If not found then the message will be looked up in the
+     * <tt>/click-control.properties</tt> file using the same key. If still
+     * not found the placeholder will be left as null and will not be rendered.
+     *
+     * @return the input field HTML5 placeholder attribute
+     */
+    public String getPlaceholder() {
+        if (placeholder == null) {
+            placeholder = getMessage(getName() + ".placeholder");
+        }
+        return placeholder;
+    }
+
+    /**
+     * Set the input field HTML5 placeholder attribute.
+     *
+     * @param value the input field HTML5 placeholder attribute.
+     */
+    public void setPlaceholder(String value) {
+        this.placeholder = value;
+    }
+
+    /**
      * Return the field size.
      *
      * @return the field size
@@ -316,6 +376,9 @@
         if (getMaxLength() > 0) {
             buffer.appendAttribute("maxlength", getMaxLength());
         }
+        if (getFocus()) {
+            buffer.appendAttribute("autofocus", "autofocus");
+        }
 
         if (isValid()) {
             removeStyleClass("error");
@@ -330,6 +393,12 @@
 
         appendAttributes(buffer);
 
+        if (!hasAttribute("placeholder")) {
+            if (getPlaceholder() != null) {
+                buffer.appendAttribute("placeholder", getPlaceholder());
+            }
+        }
+
         if (isDisabled()) {
             buffer.appendAttributeDisabled();
         }