1 33 34 package com.icesoft.faces.component.panelpopup; 35 36 import com.icesoft.faces.component.ext.renderkit.GroupRenderer; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 import com.icesoft.faces.component.util.CustomComponentUtils; 39 import com.icesoft.faces.context.DOMContext; 40 import com.icesoft.faces.context.effects.CurrentStyle; 41 import com.icesoft.faces.context.effects.JavascriptContext; 42 import com.icesoft.faces.renderkit.dom_html_basic.HTML; 43 import com.icesoft.faces.renderkit.dom_html_basic.PassThruAttributeRenderer; 44 import com.icesoft.faces.util.CoreUtils; 45 46 import org.apache.commons.logging.Log; 47 import org.apache.commons.logging.LogFactory; 48 import org.w3c.dom.Element ; 49 import org.w3c.dom.Node ; 50 import org.w3c.dom.NodeList ; 51 52 import javax.faces.component.UIComponent; 53 import javax.faces.context.FacesContext; 54 import java.io.IOException ; 55 56 60 public class PanelPopupRenderer extends GroupRenderer { 61 private static Log log = LogFactory.getLog(PanelPopupRenderer.class); 62 63 66 public boolean getRendersChildren() { 67 return true; 68 } 69 70 73 public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) 74 throws IOException { 75 validateParameters(facesContext, uiComponent, PanelPopup.class); 76 77 String styleClass = 78 (String ) uiComponent.getAttributes().get("styleClass"); 79 String headerClass = 80 (String ) uiComponent.getAttributes().get("headerClass"); 81 String bodyClass = 82 (String ) uiComponent.getAttributes().get("bodyClass"); 83 Boolean resizable = 84 null; Boolean modal = (Boolean ) uiComponent.getAttributes().get("modal"); 86 if (log.isTraceEnabled()) { 87 log.trace("Value of modal is [" + modal + "]"); 88 } 89 Boolean visible = (Boolean ) uiComponent.getAttributes().get("visible"); 90 91 String dndType = getDndType(uiComponent); 92 93 DOMContext domContext = 94 DOMContext.attachDOMContext(facesContext, uiComponent); 95 96 PanelPopup panelPopup = (PanelPopup) uiComponent; 98 99 String clientId = uiComponent.getClientId(facesContext); 100 101 if (!domContext.isInitialized()) { 102 Element rootDiv = domContext.createRootElement(HTML.DIV_ELEM); 103 setRootElementId(facesContext, rootDiv, uiComponent); 104 rootDiv.setAttribute(HTML.NAME_ATTR, clientId); 105 Element table = domContext.createElement(HTML.TABLE_ELEM); 106 table.setAttribute(HTML.CELLPADDING_ATTR, "0"); 107 table.setAttribute(HTML.CELLSPACING_ATTR, "0"); 108 table.setAttribute(HTML.WIDTH_ATTR, "100%"); 109 110 rootDiv.appendChild(table); 111 if (modal != null && modal.booleanValue()) { 112 dndType = null; 113 } 114 if (dndType != null) { 116 Element statusField = createHiddenField(domContext, 118 facesContext, 119 uiComponent, STATUS); 120 rootDiv.appendChild(statusField); 121 Element targetID = createHiddenField(domContext, facesContext, 122 uiComponent, DROP); 123 rootDiv.appendChild(targetID); 124 } 125 String script = 127 modalJavascript(modal, visible, facesContext, clientId); 128 if (script != null) { 129 Element scriptEle = domContext.createElement(HTML.SCRIPT_ELEM); 130 scriptEle.setAttribute(HTML.SCRIPT_LANGUAGE_ATTR, 131 HTML.SCRIPT_LANGUAGE_JAVASCRIPT); 132 script = "window.onLoad(function(){" + script + "});"; 133 Node node = domContext.createTextNode(script); 134 scriptEle.appendChild(node); 135 rootDiv.appendChild(scriptEle); 136 } 137 } 138 139 Element root = (Element ) domContext.getRootNode(); 140 String style = ((PanelPopup) uiComponent).getStyle(); 141 if(style != null && style.length() > 0) 142 root.setAttribute(HTML.STYLE_ATTR, style); 143 else 144 root.removeAttribute(HTML.STYLE_ATTR); 145 try { 146 root.setAttribute(HTML.CLASS_ATTR, styleClass); 147 String script = 148 modalJavascript(modal, visible, facesContext, clientId); 149 if (script != null) { 150 JavascriptContext.addJavascriptCall(facesContext, script); 151 } 152 } catch (Exception e) { 153 log.error("Error rendering Modal Panel Popup ", e); 154 } 155 NodeList tables = root.getElementsByTagName(HTML.TABLE_ELEM); 157 Element table = (Element ) tables.item(0); 159 DOMContext.removeChildrenByTagName(table, HTML.TR_ELEM); 161 162 PassThruAttributeRenderer 163 .renderAttributes(facesContext, uiComponent, null); 164 String handleId = null; 165 if (panelPopup.getHeader() != null) { 166 Element headerTr = domContext.createElement(HTML.TR_ELEM); 167 Element headerTd = domContext.createElement(HTML.TD_ELEM); 168 headerTd.setAttribute(HTML.CLASS_ATTR, headerClass); 169 handleId = uiComponent.getClientId(facesContext) + "Handle"; 170 headerTd.setAttribute(HTML.ID_ATTR, handleId); 171 headerTr.appendChild(headerTd); 172 table.appendChild(headerTr); 174 domContext.setCursorParent(headerTd); 177 178 UIComponent header = panelPopup.getHeader(); 179 180 domContext.streamWrite(facesContext, uiComponent, 181 domContext.getRootNode(), headerTd); 182 183 CustomComponentUtils.renderChild(facesContext, header); 184 } 185 186 if (panelPopup.getBody() != null) { 187 188 Element bodyTr = domContext.createElement(HTML.TR_ELEM); 189 Element bodyTd = domContext.createElement(HTML.TD_ELEM); 190 191 192 bodyTd.setAttribute(HTML.CLASS_ATTR, bodyClass); 193 bodyTr.appendChild(bodyTd); 194 table.appendChild(bodyTr); 196 domContext.setCursorParent(bodyTd); 200 201 UIComponent body = panelPopup.getBody(); 202 203 domContext.streamWrite(facesContext, uiComponent, 204 domContext.getRootNode(), bodyTd); 205 206 CustomComponentUtils.renderChild(facesContext, body); 207 } 208 if (resizable != null && resizable.booleanValue()) { 210 Element footerTr = domContext.createElement(HTML.TR_ELEM); 211 footerTr.setAttribute(HTML.HEIGHT_ATTR, "15px"); 212 footerTr.setAttribute(HTML.STYLE_ATTR, 213 "text-align: right; float: right;"); 214 Element footerTd = domContext.createElement(HTML.TD_ELEM); 215 footerTd.setAttribute(HTML.STYLE_CLASS_ATTR, "panelPopupFooter"); 216 Element img = domContext.createElement(HTML.IMG_ELEM); 217 img.setAttribute(HTML.SRC_ATTR, CoreUtils 218 .resolveResourceURL(facesContext, 219 "/xmlhttp/css/xp/css-images/resize.gif")); 220 img.setAttribute(HTML.STYLE_ATTR, "cursor: se-resize"); 221 footerTd.appendChild(img); 222 footerTr.appendChild(footerTd); 223 table.appendChild(footerTr); 224 } 225 226 domContext.stepOver(); 227 domContext.streamWrite(facesContext, uiComponent); 228 CurrentStyle.apply(facesContext, uiComponent); 229 if (dndType != null) { 231 addJavascriptCalls(uiComponent, "DRAG", handleId, facesContext); 232 } 233 } 234 235 private String modalJavascript(Boolean modal, Boolean visible, 236 FacesContext facesContext, String clientId) { 237 String call = null; 238 if (modal != null) { 239 if (modal.booleanValue() && visible.booleanValue()) { 240 call = "Ice.modal.start('" + clientId + "');"; 241 if (log.isTraceEnabled()) { 242 log.trace("Starting Modal Function"); 243 } 244 } else { 245 call = "Ice.modal.stop('" + clientId + "');"; 246 if (log.isTraceEnabled()) { 247 log.trace("Stopping modal function"); 248 } 249 } 250 } 251 return call; 252 } 253 254 257 public void encodeChildren(FacesContext facesContext, 258 UIComponent uiComponent) throws IOException { 259 } 260 261 264 public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) 265 throws IOException { 266 if (log.isTraceEnabled()) { 267 log.trace("Encode End Called"); 268 } 269 } 270 } | Popular Tags |