001: /*
002: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003: *
004: * "The contents of this file are subject to the Mozilla Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License at
007: * http://www.mozilla.org/MPL/
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
011: * License for the specific language governing rights and limitations under
012: * the License.
013: *
014: * The Original Code is ICEfaces 1.5 open source software code, released
015: * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
016: * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
017: * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
018: *
019: * Contributor(s): _____________________.
020: *
021: * Alternatively, the contents of this file may be used under the terms of
022: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
023: * License), in which case the provisions of the LGPL License are
024: * applicable instead of those above. If you wish to allow use of your
025: * version of this file only under the terms of the LGPL License and not to
026: * allow others to use your version of this file under the MPL, indicate
027: * your decision by deleting the provisions above and replace them with
028: * the notice and other provisions required by the LGPL License. If you do
029: * not delete the provisions above, a recipient may use your version of
030: * this file under either the MPL or the LGPL License."
031: *
032: */
033:
034: package com.icesoft.faces.renderkit.dom_html_basic;
035:
036: import com.icesoft.faces.context.DOMContext;
037: import org.w3c.dom.Element;
038:
039: import javax.faces.component.UIComponent;
040: import javax.faces.component.UIInput;
041: import javax.faces.context.FacesContext;
042: import java.io.IOException;
043: import java.util.HashSet;
044:
045: public class SecretRenderer extends DomBasicInputRenderer {
046:
047: public void encodeBegin(FacesContext facesContext,
048: UIComponent uiComponent) throws IOException {
049: validateParameters(facesContext, uiComponent, UIInput.class);
050: }
051:
052: public void encodeChildren(FacesContext facesContext,
053: UIComponent uiComponent) throws IOException {
054: validateParameters(facesContext, uiComponent, UIInput.class);
055: }
056:
057: protected void renderEnd(FacesContext facesContext,
058: UIComponent uiComponent, String currentValue)
059: throws IOException {
060:
061: validateParameters(facesContext, uiComponent, UIInput.class);
062:
063: DOMContext domContext = DOMContext.attachDOMContext(
064: facesContext, uiComponent);
065:
066: if (!domContext.isInitialized()) {
067: Element root = domContext.createElement("input");
068: domContext.setRootNode(root);
069: setRootElementId(facesContext, root, uiComponent);
070: root.setAttribute("type", "password");
071: root.setAttribute("name", uiComponent
072: .getClientId(facesContext));
073: }
074:
075: Element root = (Element) domContext.getRootNode();
076:
077: String dir = (String) uiComponent.getAttributes().get("dir");
078: if (dir != null) {
079: root.setAttribute("dir", dir);
080: }
081:
082: String styleClass = (String) uiComponent.getAttributes().get(
083: "styleClass");
084: if (styleClass != null) {
085: root.setAttribute("class", styleClass);
086: }
087: PassThruAttributeRenderer.renderAttributes(facesContext,
088: uiComponent, null);
089:
090: // render the current value of the component as the value of the "value"
091: // attribute if and only if the value of the component attribute
092: // "redisplay" is the string "true"
093: if (redisplayAttributeIsTrue(uiComponent)
094: && currentValue != null) {
095: root.setAttribute("value", currentValue);
096: } else {
097: root.setAttribute("value", "");
098: }
099:
100: HashSet excludes = new HashSet();
101: addJavaScript(facesContext, uiComponent, root, excludes);
102: domContext.streamWrite(facesContext, uiComponent);
103: }
104:
105: /**
106: * @param uiComponent
107: * @return boolean
108: */
109: private boolean redisplayAttributeIsTrue(UIComponent uiComponent) {
110: Object redisplayAttribute = uiComponent.getAttributes().get(
111: "redisplay");
112: return redisplayAttribute != null
113: && redisplayAttribute.toString().toLowerCase().equals(
114: "true");
115: }
116:
117: protected void addJavaScript(FacesContext facesContext,
118: UIComponent uiComponent, Element root, HashSet excludes) {
119: }
120: }
|