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.ext.HtmlCommandLink;
037: import com.icesoft.faces.renderkit.dom_html_basic.HTML;
038:
039: import org.w3c.dom.Element;
040:
041: import javax.faces.FacesException;
042: import javax.faces.component.UICommand;
043: import javax.faces.component.UIComponent;
044: import javax.faces.context.FacesContext;
045: import java.io.IOException;
046: import java.util.Map;
047:
048: public class CommandLinkRenderer extends
049: com.icesoft.faces.renderkit.dom_html_basic.CommandLinkRenderer {
050:
051: public void encodeBegin(FacesContext facesContext,
052: UIComponent uiComponent) throws IOException {
053:
054: super .encodeBegin(facesContext, uiComponent);
055: }
056:
057: public void renderOnClick(FacesContext facesContext,
058: UIComponent uiComponent, Element root, Map parameters) {
059: HtmlCommandLink link = (HtmlCommandLink) uiComponent;
060: if (link.isDisabled()) {
061: root.removeAttribute("onclick");
062: } else if (link.getPartialSubmit()) {
063: UIComponent uiForm = findForm(uiComponent);
064: if (uiForm == null) {
065: throw new FacesException(
066: "CommandLink must be contained in a form");
067: }
068: String uiFormClientId = uiForm.getClientId(facesContext);
069:
070: Object passThruOnClick = uiComponent.getAttributes().get(
071: HTML.ONCLICK_ATTR);
072:
073: String onClick = "";
074: // if onClick attribute set by the user, pre append it.
075: if (passThruOnClick != null) {
076: onClick = passThruOnClick.toString()
077: + ";"
078: + this .getJavaScriptPartialOnClickString(
079: facesContext, uiComponent,
080: uiFormClientId, parameters);
081: } else {
082: onClick = this .getJavaScriptPartialOnClickString(
083: facesContext, uiComponent, uiFormClientId,
084: parameters);
085: }
086: root.setAttribute("onclick", onClick);
087: } else {
088: super .renderOnClick(facesContext, uiComponent, root,
089: parameters);
090: }
091: }
092:
093: private String getJavaScriptPartialOnClickString(
094: FacesContext facesContext, UIComponent uiComponent,
095: String formClientId, Map parameters) {
096: return com.icesoft.faces.renderkit.dom_html_basic.CommandLinkRenderer
097: .getJavascriptHiddenFieldSetters(facesContext,
098: (UICommand) uiComponent, formClientId,
099: parameters)
100: + "iceSubmitPartial("
101: + " document.forms['"
102: + formClientId
103: + "'],"
104: + " this,event); "
105: + "return false;";
106: }
107:
108: }
|