001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.el.MethodBinding;
047: import javax.faces.el.ValueBinding;
048:
049: /**
050: * <p> Use the <code>ui:passwordField</code> tag to create an input
051: * field where the characters entered are echoed back with a
052: * replacement character, so as to mask the input. </p>
053: *
054: * <h3>HTML Elements and Layout</h3>
055: *
056: * <p>The textField component renders an XHTML <code><input
057: * type="password"></code> element.</p>
058: *
059: * <h3>Configuring the <code>ui:passwordField</code> Tag</h3>
060: *
061: * <p>Use the <code>password</code> attribute to associate
062: * the component with a model object that represents the current value,
063: * by setting the attribute's value to an EL expression that corresponds
064: * to a property of a managed bean.</p>
065: *
066: * <p>To optionally specify a label for the component, use the
067: * <code>label</code> attribute, or specify a label facet. </p>
068: *
069: * <h3>Facets</h3>
070: *
071: * <ul>
072: * <li><code>label</code>: use this facet to specify a custom
073: * component for the label.</li>
074: * <li><code>readOnly</code>: use this facet to specify a custom
075: * component for displaying the value of this component when it is
076: * marked as readonly. The default is a <code>ui:staticText</code>. </li>
077: *
078: * </ul>
079: *
080: * <h3>Theme Identifiers</h3>
081: *
082: * <p>The input element has a style class "TxtFld", or "TxtFldDis"
083: * when the field is disabled. If a label attribute is specified, the
084: * label element's class attribute is set to "LblLvl1Txt", "LblLvl2Txt" or
085: * "LblLvl3Txt" depending on the label level.</p>
086: *
087: *
088: * <h3>Client-side JavaScript functions</h3>
089: *
090: * <p>In all the functions below, <code><id></code> should be
091: * the generated id of the PasswordField component. </p>
092: *
093: * <table cellpadding="2" cellspacing="2" border="1"
094: * style="text-align: left; width: 100%;">
095: * <tbody>
096: * <tr>
097: * <td style="vertical-align">
098: * <code>field_setDisabled(<id>, <disabled>)</code>
099: * </td>
100: * <td style="vertical-align: top">
101: * Enable/disable the field. Set <code><disabled></code>
102: * to true to disable the component, or false to enable it.
103: * </td>
104: * </tr> <tr>
105: * <td style="vertical-align: top">
106: * <code>field_setValue(<id>, <newValue>)</code>
107: * </td>
108: * <td style="vertical-align: top">
109: * Set the value of the field to <code><newValue></code>.
110: * </td>
111: * </tr>
112: * <tr>
113: * <td style="vertical-align: top">
114: * <code>field_getValue(<id>)</code>
115: * </td>
116: * <td style="vertical-align: top">Get the value of the field.</td>
117: * </tr>
118: * <tr>
119: * <td style="vertical-align: top">
120: * <code>field_getInputElement(<id>)</code></td>
121: * <td style="vertical-align: top">
122: * Get hold of a reference to the input element rendered by this
123: * component.
124: * </td>
125: * </tr>
126: * <tr>
127: * <td style="vertical-align: top">
128: * <code>component_setVisible(<id>)</code>
129: * </td>
130: * <td style="vertical-align: top">Hide or show this component.
131: * </td>
132: * </tr>
133: * </tbody>
134: * </table>
135: *
136: * <h3>Example</h3>
137: *
138: * <p>This example uses a backing bean <code>User</code> with a
139: * property <code>password</code>. The tag generates a label followed by
140: * text input field. The required attribute is set to true, which causes
141: * an icon to be rendered next to the label to indicate that the
142: * application user must enter a value in the text field. The icon, label
143: * and input elements are enclosed by a span.</p>
144: * <pre>
145: * <ui:passwordField id="password"
146: * password="#{User.password}"
147: * label="Password:"
148: * required="true"/>
149: * </pre>
150: * <p>Auto-generated component class.
151: * Do <strong>NOT</strong> modify; all changes
152: * <strong>will</strong> be lost!</p>
153: */
154:
155: public abstract class PasswordFieldBase extends
156: com.sun.rave.web.ui.component.Field {
157:
158: /**
159: * <p>Construct a new <code>PasswordFieldBase</code>.</p>
160: */
161: public PasswordFieldBase() {
162: super ();
163: setRendererType("com.sun.rave.web.ui.PasswordField");
164: }
165:
166: /**
167: * <p>Return the identifier of the component family to which this
168: * component belongs. This identifier, in conjunction with the value
169: * of the <code>rendererType</code> property, may be used to select
170: * the appropriate {@link Renderer} for this component instance.</p>
171: */
172: public String getFamily() {
173: return "com.sun.rave.web.ui.PasswordField";
174: }
175:
176: /**
177: * <p>Return the <code>ValueBinding</code> stored for the
178: * specified name (if any), respecting any property aliases.</p>
179: *
180: * @param name Name of value binding to retrieve
181: */
182: public ValueBinding getValueBinding(String name) {
183: if (name.equals("password")) {
184: return super .getValueBinding("text");
185: }
186: return super .getValueBinding(name);
187: }
188:
189: /**
190: * <p>Set the <code>ValueBinding</code> stored for the
191: * specified name (if any), respecting any property
192: * aliases.</p>
193: *
194: * @param name Name of value binding to set
195: * @param binding ValueBinding to set, or null to remove
196: */
197: public void setValueBinding(String name, ValueBinding binding) {
198: if (name.equals("password")) {
199: super .setValueBinding("text", binding);
200: return;
201: }
202: super .setValueBinding(name, binding);
203: }
204:
205: // password
206: /**
207: * <p>Literal value to be rendered in this input field. If this property is specified by a value binding
208: * expression, the corresponding value will be updated if validation succeeds.</p>
209: */
210: public Object getPassword() {
211: return getText();
212: }
213:
214: /**
215: * <p>Literal value to be rendered in this input field. If this property is specified by a value binding
216: * expression, the corresponding value will be updated if validation succeeds.</p>
217: * @see #getPassword()
218: */
219: public void setPassword(Object password) {
220: setText(password);
221: }
222:
223: /**
224: * <p>Restore the state of this component.</p>
225: */
226: public void restoreState(FacesContext _context, Object _state) {
227: Object _values[] = (Object[]) _state;
228: super .restoreState(_context, _values[0]);
229: }
230:
231: /**
232: * <p>Save the state of this component.</p>
233: */
234: public Object saveState(FacesContext _context) {
235: Object _values[] = new Object[1];
236: _values[0] = super.saveState(_context);
237: return _values;
238: }
239:
240: }
|