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.HtmlInputText;
038: import com.icesoft.faces.component.ext.KeyEvent;
039: import com.icesoft.faces.component.ext.taglib.Util;
040: import org.w3c.dom.Element;
041:
042: import javax.faces.component.UIComponent;
043: import javax.faces.context.FacesContext;
044: import javax.faces.event.ActionEvent;
045: import java.util.HashSet;
046:
047: public class TextRenderer extends
048: com.icesoft.faces.renderkit.dom_html_basic.TextRenderer {
049: protected void addJavaScript(FacesContext facesContext,
050: UIComponent uiComponent, Element root, String currentValue,
051: HashSet excludes) {
052: //exclude following events
053: excludes.add("onkeypress");
054: excludes.add("onfocus");
055: excludes.add("onblur");
056:
057: String onkeypress = ((HtmlInputText) uiComponent)
058: .getOnkeypress() != null ? ((HtmlInputText) uiComponent)
059: .getOnkeypress()
060: : "";
061: String onfocus = ((HtmlInputText) uiComponent).getOnfocus() != null ? ((HtmlInputText) uiComponent)
062: .getOnfocus()
063: : "";
064: String onblur = ((HtmlInputText) uiComponent).getOnblur() != null ? ((HtmlInputText) uiComponent)
065: .getOnblur()
066: : "";
067:
068: //Add the enter key behavior by default
069: root.setAttribute("onkeypress", onkeypress + this .ICESUBMIT);
070: // set the focus id
071: root.setAttribute("onfocus", onfocus + "setFocus(this.id);");
072: // clear focus id
073: root.setAttribute("onblur", onblur + "setFocus('');");
074:
075: if (((IceExtended) uiComponent).getPartialSubmit()) {
076: root
077: .setAttribute(
078: "onblur",
079: onblur
080: + "setFocus('');"
081: + "iceSubmitPartial(form,this,event); return false;");
082: }
083:
084: }
085:
086: public void decode(FacesContext facesContext,
087: UIComponent uiComponent) {
088: super .decode(facesContext, uiComponent);
089: Object focusId = facesContext.getExternalContext()
090: .getRequestParameterMap().get(
091: FormRenderer.getFocusElementId());
092: if (focusId != null) {
093: if (focusId.toString().equals(
094: uiComponent.getClientId(facesContext))) {
095: ((HtmlInputText) uiComponent).setFocus(true);
096: } else {
097: ((HtmlInputText) uiComponent).setFocus(false);
098: }
099: }
100:
101: if (Util.isEventSource(facesContext, uiComponent)) {
102: queueEventIfEnterKeyPressed(facesContext, uiComponent);
103: }
104: }
105:
106: public void queueEventIfEnterKeyPressed(FacesContext facesContext,
107: UIComponent uiComponent) {
108: try {
109: KeyEvent keyEvent = new KeyEvent(uiComponent, facesContext
110: .getExternalContext().getRequestParameterMap());
111: if (keyEvent.getKeyCode() == KeyEvent.CARRIAGE_RETURN) {
112: uiComponent.queueEvent(new ActionEvent(uiComponent));
113: }
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: }
118:
119: }
|