1 16 package org.apache.myfaces.custom.div; 17 18 import java.io.IOException ; 19 20 import javax.faces.component.UIComponent; 21 import javax.faces.context.FacesContext; 22 import javax.faces.context.ResponseWriter; 23 24 import org.apache.myfaces.renderkit.html.HTML; 25 import org.apache.myfaces.renderkit.html.HtmlRenderer; 26 import org.apache.myfaces.renderkit.html.HtmlRendererUtils; 27 47 public class DivRenderer extends HtmlRenderer { 48 public static final String RENDERER_TYPE = "org.apache.myfaces.DivRenderer"; 49 50 public void encodeBegin(FacesContext context, UIComponent component) 51 throws IOException { 52 if ((context == null) || (component == null)) { 53 throw new NullPointerException (); 54 } 55 Div div = (Div) component; 56 ResponseWriter writer = context.getResponseWriter(); 57 58 writer.startElement(HTML.DIV_ELEM, component); 59 HtmlRendererUtils.writeIdIfNecessary(writer, component, context); 60 61 String styleClass = div.getStyleClass(); 62 String style = div.getStyle(); 63 if(null != styleClass && null != style) { 64 throw new IllegalStateException ("Only one of style or styleClass can be specified"); 65 } 66 if(null != styleClass) { 67 writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null); 68 } 69 if(null != style) { 70 writer.writeAttribute(HTML.STYLE_ATTR, style, null); 71 } 72 } 73 74 public void encodeEnd(FacesContext context, UIComponent component) 75 throws IOException { 76 if ((context == null) || (component == null)) { 77 throw new NullPointerException (); 78 } 79 ResponseWriter writer = context.getResponseWriter(); 80 writer.endElement(HTML.DIV_ELEM); 81 } 82 } | Popular Tags |