1 28 29 package com.caucho.jsf.html; 30 31 import java.io.*; 32 import java.util.*; 33 34 import javax.faces.*; 35 import javax.faces.component.*; 36 import javax.faces.component.html.*; 37 import javax.faces.context.*; 38 import javax.faces.render.*; 39 40 43 class HtmlPanelGridRenderer extends Renderer 44 { 45 public static final Renderer RENDERER = new HtmlPanelGridRenderer(); 46 47 50 @Override 51 public boolean getRendersChildren() 52 { 53 return true; 54 } 55 58 @Override 59 public void encodeBegin(FacesContext context, UIComponent component) 60 throws IOException 61 { 62 ResponseWriter out = context.getResponseWriter(); 63 64 String bgcolor = null; 65 int border = -1; 66 String cellpadding = null; 67 String cellspacing = null; 68 String dir = null; 69 String frame = null; 70 String lang = null; 71 String onclick = null; 72 String ondblclick = null; 73 String onkeydown = null; 74 String onkeypress = null; 75 String onkeyup = null; 76 String onmousedown = null; 77 String onmousemove = null; 78 String onmouseout = null; 79 String onmouseover = null; 80 String onmouseup = null; 81 String rules = null; 82 String style = null; 83 String styleClass = null; 84 String summary = null; 85 String title = null; 86 String width = null; 87 88 if (component instanceof HtmlPanelGrid) { 89 HtmlPanelGrid html = (HtmlPanelGrid) component; 90 91 bgcolor = html.getBgcolor(); 92 border = html.getBorder(); 93 cellpadding = html.getCellpadding(); 94 cellspacing = html.getCellspacing(); 95 dir = html.getDir(); 96 frame = html.getFrame(); 97 lang = html.getLang(); 98 onclick = html.getOnclick(); 99 ondblclick = html.getOndblclick(); 100 onkeydown = html.getOnkeydown(); 101 onkeypress = html.getOnkeypress(); 102 onkeyup = html.getOnkeyup(); 103 onmousedown = html.getOnmousedown(); 104 onmousemove = html.getOnmousemove(); 105 onmouseout = html.getOnmouseout(); 106 onmouseover = html.getOnmouseover(); 107 onmouseup = html.getOnmouseup(); 108 rules = html.getRules(); 109 style = html.getStyle(); 110 styleClass = html.getStyleClass(); 111 summary = html.getSummary(); 112 title = html.getTitle(); 113 width = html.getWidth(); 114 } 115 else { 116 Map<String ,Object > attrMap = component.getAttributes(); 117 118 bgcolor = (String ) attrMap.get("bgcolor"); 119 style = (String ) attrMap.get("style"); 120 styleClass = (String ) attrMap.get("styleClass"); 121 } 122 123 out.startElement("table", component); 124 125 if (bgcolor != null) 126 out.writeAttribute("bgcolor", bgcolor, "bgcolor"); 127 128 if (border >= 0) 129 out.writeAttribute("border", border, "border"); 130 131 if (cellpadding != null) 132 out.writeAttribute("cellpadding", cellpadding, "cellpadding"); 133 134 if (cellspacing != null) 135 out.writeAttribute("cellspacing", cellspacing, "cellspacing"); 136 137 if (dir != null) 138 out.writeAttribute("dir", dir, "dir"); 139 140 if (frame != null) 141 out.writeAttribute("frame", frame, "frame"); 142 143 if (lang != null) 144 out.writeAttribute("lang", lang, "lang"); 145 146 if (onclick != null) 147 out.writeAttribute("onclick", onclick, "onclick"); 148 149 if (ondblclick != null) 150 out.writeAttribute("ondblclick", ondblclick, "ondblclick"); 151 152 if (onkeydown != null) 153 out.writeAttribute("onkeydown", onkeydown, "onkeydown"); 154 155 if (onkeypress != null) 156 out.writeAttribute("onkeypress", onkeypress, "onkeypress"); 157 158 if (onkeyup != null) 159 out.writeAttribute("onkeyup", onkeyup, "onkeyup"); 160 161 if (onmousedown != null) 162 out.writeAttribute("onmousedown", onmousedown, "onmousedown"); 163 164 if (onmousemove != null) 165 out.writeAttribute("onmousemove", onmousemove, "onmousemove"); 166 167 if (onmouseout != null) 168 out.writeAttribute("onmouseout", onmouseout, "onmouseout"); 169 170 if (onmouseover != null) 171 out.writeAttribute("onmouseover", onmouseover, "onmouseover"); 172 173 if (onmouseup != null) 174 out.writeAttribute("onmouseup", onmouseup, "onmouseup"); 175 176 if (rules != null) 177 out.writeAttribute("rules", rules, "rules"); 178 179 if (style != null) 180 out.writeAttribute("style", style, "style"); 181 182 if (styleClass != null) 183 out.writeAttribute("class", styleClass, "styleClass"); 184 185 if (summary != null) 186 out.writeAttribute("summary", summary, "summary"); 187 188 if (title != null) 189 out.writeAttribute("title", title, "title"); 190 191 if (width != null) 192 out.writeAttribute("width", width, "width"); 193 } 194 195 196 199 @Override 200 public void encodeChildren(FacesContext context, UIComponent component) 201 throws IOException 202 { 203 ResponseWriter out = context.getResponseWriter(); 204 205 int columns = 0; 206 207 if (component instanceof HtmlPanelGrid) { 208 HtmlPanelGrid html = (HtmlPanelGrid) component; 209 210 columns = html.getColumns(); 211 } 212 else { 213 Map<String ,Object > attrMap = component.getAttributes(); 214 215 columns = (Integer ) attrMap.get("columns"); 216 } 217 218 int size = component.getChildCount(); 219 if (size == 0) 220 return; 221 222 if (columns < 1) 223 columns = 1; 224 225 List<UIComponent> children = component.getChildren(); 226 int count = 0; 227 228 for (int i = 0; i < size; i++) { 229 UIComponent child = children.get(i); 230 231 if (! child.isRendered()) 232 continue; 233 234 if (count % columns == 0) { 235 if (count > 0) { 236 out.endElement("tr"); 237 } 238 239 out.startElement("tr", child); 240 } 241 242 count++; 243 244 out.startElement("td", child); 245 child.encodeBegin(context); 246 child.encodeChildren(context); 247 child.encodeEnd(context); 248 out.endElement("td"); 249 } 250 251 if (count > 0) 252 out.endElement("tr"); 253 } 254 255 258 @Override 259 public void encodeEnd(FacesContext context, UIComponent component) 260 throws IOException 261 { 262 ResponseWriter out = context.getResponseWriter(); 263 264 out.endElement("table"); 265 } 266 267 public String toString() 268 { 269 return "HtmlPanelGridRenderer[]"; 270 } 271 } 272 | Popular Tags |