From 445f4c115cfb4e5a6ec512a42dcb4eb2b34e9d68 Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 1 Nov 2001 00:22:48 +0000 Subject: [PATCH] Extracted common code, added support for password input fields. git-svn-id: https://samskivert.googlecode.com/svn/trunk@402 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/velocity/FormTool.java | 97 +++++++++++++------ 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/velocity/FormTool.java b/projects/samskivert/src/java/com/samskivert/velocity/FormTool.java index 4eb25fa4..311a78e4 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/FormTool.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/FormTool.java @@ -1,5 +1,5 @@ // -// $Id: FormTool.java,v 1.1 2001/10/31 11:07:55 mdb Exp $ +// $Id: FormTool.java,v 1.2 2001/11/01 00:22:48 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -55,22 +55,22 @@ public class FormTool * Creates a text input field with the specified name and no extra * arguments or default value. * - * @see #text(String,String,String) + * @see #text(String,String,Object) */ public String text (String name) { - return text(name, "", ""); + return input("text", name, "", ""); } /** * Creates a text input field with the specified name and the * specified extra arguments with no default value. * - * @see #text(String,String,String) + * @see #text(String,String,Object) */ public String text (String name, String extra) { - return text(name, extra, ""); + return input("text", name, extra, ""); } /** @@ -85,25 +85,49 @@ public class FormTool * * Assuming the foo parameter had no pre-existing value. */ - public String text (String name, String extra, Object defaultValue) + public String text (String name, String extra, + Object defaultValue) { - StringBuffer buf = new StringBuffer(); - buf.append(""); - return buf.toString(); + /** + * Creates a password input field with the specified name, extra arguments + * and default value. For example, a call to password("foo", + * "size=\"5\"", "bar") would result in an + * input field looking like: + * + *
+     * <input type="password" name="foo" value="bar" size="5">
+     * 
+ * + * Assuming the foo parameter had no pre-existing value. + */ + public String password (String name, String extra, Object defaultValue) + { + return input("password", name, extra, defaultValue); } /** @@ -112,12 +136,7 @@ public class FormTool */ public String submit (String name, String text) { - StringBuffer buf = new StringBuffer(); - buf.append(""); - return buf.toString(); + return fixedInput("submit", name, text, ""); } /** @@ -146,11 +165,35 @@ public class FormTool * ignored when creating this element. */ public String fixedHidden (String name, String value) + { + return fixedInput("hidden", name, value, ""); + } + + /** + * Generates an input form field with the specified type, name, + * defaultValue and extra attributes. + */ + protected String input (String type, String name, String extra, + Object defaultValue) + { + return fixedInput(type, name, getValue(name, defaultValue), extra); + } + + /** + * Generates an input form field with the specified type, name, value + * and extra attributes. The value is not fetched from the request + * parameters but is always the value supplied. + */ + protected String fixedInput ( + String type, String name, String value, String extra) { StringBuffer buf = new StringBuffer(); - buf.append(""); return buf.toString(); }