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.component.ext.renderkit;
035:
036: import com.icesoft.faces.component.IceExtended;
037: import com.icesoft.faces.component.ext.HtmlInputSecret;
038: import com.icesoft.faces.component.ext.KeyEvent;
039: import com.icesoft.faces.component.ext.taglib.Util;
040: import com.icesoft.faces.component.menubar.MenuItem;
041: import com.icesoft.faces.context.DOMContext;
042: import com.icesoft.faces.renderkit.dom_html_basic.PassThruAttributeRenderer;
043:
044: import org.w3c.dom.Element;
045:
046: import javax.faces.component.UIComponent;
047: import javax.faces.component.UIInput;
048: import javax.faces.context.FacesContext;
049: import javax.faces.event.ActionEvent;
050:
051: import java.io.IOException;
052: import java.util.HashSet;
053: import java.util.Map;
054:
055: public class SecretRenderer extends
056: com.icesoft.faces.renderkit.dom_html_basic.SecretRenderer {
057:
058: protected void addJavaScript(FacesContext facesContext,
059: UIComponent uiComponent, Element root, HashSet excludes) {
060:
061: //exclude following events
062: excludes.add("onkeypress");
063: excludes.add("onfocus");
064: excludes.add("onblur");
065:
066: String onkeypress = ((HtmlInputSecret) uiComponent)
067: .getOnkeypress() != null ? ((HtmlInputSecret) uiComponent)
068: .getOnkeypress()
069: : "";
070: String onfocus = ((HtmlInputSecret) uiComponent).getOnfocus() != null ? ((HtmlInputSecret) uiComponent)
071: .getOnfocus()
072: : "";
073: String onblur = ((HtmlInputSecret) uiComponent).getOnblur() != null ? ((HtmlInputSecret) uiComponent)
074: .getOnblur()
075: : "";
076:
077: //Add the enter key behavior by default
078: root.setAttribute("onkeypress", onkeypress + this .ICESUBMIT);
079: // set the focus id
080: root.setAttribute("onfocus", onfocus + "setFocus(this.id);");
081: // clear focus id
082: root.setAttribute("onblur", onblur + "setFocus('');");
083:
084: if (((IceExtended) uiComponent).getPartialSubmit()) {
085: root
086: .setAttribute(
087: "onblur",
088: onblur
089: + "setFocus('');"
090: + "iceSubmitPartial(form,this,event); return false;");
091: }
092:
093: }
094:
095: public void decode(FacesContext facesContext,
096: UIComponent uiComponent) {
097: HtmlInputSecret inputSecret = (HtmlInputSecret) uiComponent;
098: // check if we are processing a partial submit
099: Map requestParameterMap = facesContext.getExternalContext()
100: .getRequestParameterMap();
101: String partial = "partial";
102: boolean test = Boolean.valueOf(
103: (String) requestParameterMap.get(partial))
104: .booleanValue();
105: if (test) {
106: // force the redisplay for partialSubmit enabled inputSecret components
107: if (!inputSecret.isRedisplay()) {
108: inputSecret.setRedisplay(true);
109: }
110: }
111:
112: super .decode(facesContext, uiComponent);
113: if (Util.isEventSource(facesContext, uiComponent)) {
114: queueEventIfEnterKeyPressed(facesContext, uiComponent);
115: }
116:
117: }
118:
119: public void queueEventIfEnterKeyPressed(FacesContext facesContext,
120: UIComponent uiComponent) {
121: try {
122: KeyEvent keyEvent = new KeyEvent(uiComponent, facesContext
123: .getExternalContext().getRequestParameterMap());
124: if (keyEvent.getKeyCode() == KeyEvent.CARRIAGE_RETURN) {
125: uiComponent.queueEvent(new ActionEvent(uiComponent));
126: }
127: } catch (Exception e) {
128: e.printStackTrace();
129: }
130: }
131:
132: /**
133: * @param uiComponent
134: * @return boolean
135: */
136: private boolean redisplayAttributeIsTrue(UIComponent uiComponent,
137: FacesContext facesContext) {
138: if (Util.isEventSource(facesContext, uiComponent)) {
139: return true;
140: }
141: Object redisplayAttribute = uiComponent.getAttributes().get(
142: "redisplay");
143: return redisplayAttribute != null
144: && redisplayAttribute.toString().toLowerCase().equals(
145: "true");
146: }
147:
148: }
|