KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > PasswordTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import java.io.IOException JavaDoc;
11
12 import javax.servlet.jsp.JspException JavaDoc;
13
14 import org.apache.log4j.Logger;
15
16 import com.inversoft.util.ObjectTools;
17 import com.inversoft.verge.mvc.view.HtmlViewToolkit;
18
19
20 /**
21  * This class represents an HTML password input tag.
22  *
23  * @author Brian Pontarelli
24  * @since 1.0
25  * @version 2.0
26  */

27 public class PasswordTag extends TextTag {
28
29     /**
30      * This classes logger
31      */

32     private static final Logger logger = Logger.getLogger(PasswordTag.class);
33
34     private boolean showPassword = false;
35
36
37     /**
38      * Gets the value of the showPassword attribute
39      *
40      * @return The value of the showPassword attribute
41      */

42     public boolean getShowPassword() {
43         return showPassword;
44     }
45
46     /**
47      * Sets the value of the showPassword attribute
48      *
49      * @param showPassword The new value of the showPassword attribute
50      */

51     public void setShowPassword(boolean showPassword) {
52         this.showPassword = showPassword;
53     }
54
55
56     /**
57      * Ouputs a password input tag the contains the value if set, or the current value
58      * of the bean this tag is tied to, and the name of the bean this is tied
59      * to
60      * @return Always returns SKIP_BODY
61      * @throws JspException If this tag is not inside a submit tag and the submit
62      * tag is not inside a form tag, or if a property name was not specified
63      */

64     public int doStartTag() throws JspException JavaDoc {
65
66         // Initialize the parent reference and the bean reference
67
initialize();
68
69         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
70         createPasswordTag(buf, getId(), localName, localValue);
71
72         if (logger.isDebugEnabled()) {
73             logger.debug("The password tag: " + buf.toString());
74         }
75
76         try {
77             pageContext.getOut().print(buf.toString());
78         } catch (IOException JavaDoc ioe) {
79             throw new JspException JavaDoc(ioe.toString());
80         }
81
82         return SKIP_BODY;
83     }
84
85     /**
86      * Does the work of creating the tags body. This method can be overridden
87      * in sub-classes to change the attributes that are appended, etc. By default
88      * this creates a password tag with the name, value, attributes (single and
89      * named).
90      *
91      * This method optionally sets the value of the password tag depending on the
92      * value of the showPassword Boolean. The default is to NOT show the value.
93      *
94      * @param buf The StringBuffer to append to
95      * @param id The id of the tag
96      * @param name The name of the tag
97      * @param value The value of the tag
98      */

99     protected void createPasswordTag(StringBuffer JavaDoc buf, String JavaDoc id, String JavaDoc name,
100             Object JavaDoc value)
101     throws JspException JavaDoc {
102         String JavaDoc valueStr = null;
103         if (showPassword) {
104             valueStr = ObjectTools.toString(value);
105         }
106
107         HtmlViewToolkit.createPasswordTag(buf, id, name, valueStr, attributes,
108             singleAttrs);
109     }
110 }
Popular Tags