1 33 34 package com.icesoft.faces.component.outputchart; 35 36 import com.icesoft.faces.component.ext.renderkit.FormRenderer; 37 import com.icesoft.faces.context.DOMContext; 38 import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer; 39 import com.icesoft.faces.renderkit.dom_html_basic.HTML; 40 import org.w3c.dom.Element ; 41 42 import javax.faces.component.UIComponent; 43 import javax.faces.context.FacesContext; 44 import java.io.IOException ; 45 46 public class OutputChartRenderer extends DomBasicRenderer { 47 48 public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) 49 throws IOException { 50 51 OutputChart outputChart = (OutputChart) uiComponent; 52 String clientId = outputChart.getClientId(facesContext); 53 DOMContext domContext = 54 DOMContext.attachDOMContext(facesContext, uiComponent); 55 if (!domContext.isInitialized()) { 56 Element table = domContext.createElement(HTML.TABLE_ELEM); 57 domContext.setRootNode(table); 58 setRootElementId(facesContext, table, uiComponent); 59 Element tr = (Element ) domContext.createElement(HTML.TR_ELEM); 60 Element td = (Element ) domContext.createElement(HTML.TD_ELEM); 61 table.setAttribute(HTML.CLASS_ATTR, outputChart.getStyleClass()); 62 String style = outputChart.getStyle(); 63 if(style != null && style.length() > 0) 64 table.setAttribute(HTML.STYLE_ATTR, style); 65 else 66 table.removeAttribute(HTML.STYLE_ATTR); 67 table.appendChild(tr); 68 tr.appendChild(td); 69 } 70 FormRenderer.addHiddenField(facesContext, "iceChartComponent"); 71 Element td = (Element ) domContext.getRootNode(). getFirstChild(). getFirstChild(); DOMContext.removeChildren(td); 75 td.setAttribute(HTML.WIDTH_ATTR, outputChart.getWidth()); 76 td.setAttribute(HTML.HEIGHT_ATTR, outputChart.getHeight()); 77 Element image = (Element ) domContext.createElement(HTML.IMG_ELEM); 78 79 image.setAttribute(HTML.SRC_ATTR, getResourceURL(facesContext, 80 "/"+ outputChart.getFolder().getName()+ "/" + 81 outputChart.getFileName())); 82 85 td.appendChild(image); 86 if (outputChart.isClientSideImageMap()) { 87 Element map = (Element ) domContext.createElement(HTML.MAP_ELEM); 88 map.setAttribute(HTML.NAME_ATTR, "map" + clientId); 89 image.setAttribute(HTML.USEMAP_ATTR, "#map" + clientId); 90 image.setAttribute(HTML.BORDER_ATTR, "0"); 91 outputChart.generateClientSideImageMap(domContext, map); 93 td.appendChild(map); 94 } 95 domContext.streamWrite(facesContext, uiComponent); 96 domContext.stepOver(); 97 } 98 } 99 | Popular Tags |