1 33 34 package com.icesoft.faces.component.ext.renderkit; 35 36 import com.icesoft.faces.component.ext.HtmlCommandLink; 37 import com.icesoft.faces.renderkit.dom_html_basic.HTML; 38 39 import org.w3c.dom.Element ; 40 41 import javax.faces.FacesException; 42 import javax.faces.component.UICommand; 43 import javax.faces.component.UIComponent; 44 import javax.faces.context.FacesContext; 45 import java.io.IOException ; 46 import java.util.Map ; 47 48 public class CommandLinkRenderer extends 49 com.icesoft.faces.renderkit.dom_html_basic.CommandLinkRenderer { 50 51 public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) 52 throws IOException { 53 54 super.encodeBegin(facesContext, uiComponent); 55 } 56 57 public void renderOnClick(FacesContext facesContext, 58 UIComponent uiComponent, Element root, Map parameters) { 59 HtmlCommandLink link = (HtmlCommandLink) uiComponent; 60 if (link.isDisabled()) { 61 root.removeAttribute("onclick"); 62 } else if (link.getPartialSubmit()) { 63 UIComponent uiForm = findForm(uiComponent); 64 if (uiForm == null) { 65 throw new FacesException( 66 "CommandLink must be contained in a form"); 67 } 68 String uiFormClientId = uiForm.getClientId(facesContext); 69 70 Object passThruOnClick = uiComponent.getAttributes().get( 71 HTML.ONCLICK_ATTR); 72 73 String onClick = ""; 74 if (passThruOnClick != null) { 76 onClick = passThruOnClick.toString() 77 + ";" 78 + this.getJavaScriptPartialOnClickString(facesContext, 79 uiComponent, uiFormClientId, parameters); 80 } else { 81 onClick = this.getJavaScriptPartialOnClickString(facesContext, 82 uiComponent, uiFormClientId, parameters); 83 } 84 root.setAttribute("onclick", onClick); 85 } else { 86 super.renderOnClick(facesContext, uiComponent, root, parameters); 87 } 88 } 89 90 private String getJavaScriptPartialOnClickString(FacesContext facesContext, 91 UIComponent uiComponent, String formClientId, Map parameters) { 92 return com.icesoft.faces.renderkit.dom_html_basic.CommandLinkRenderer 93 .getJavascriptHiddenFieldSetters(facesContext, 94 (UICommand) uiComponent, formClientId, parameters) 95 + "iceSubmitPartial(" 96 + " document.forms['" 97 + formClientId 98 + "']," + " this,event); " + "return false;"; 99 } 100 101 } 102 | Popular Tags |