1 16 17 package org.apache.struts.faces.renderer; 18 19 20 import java.io.IOException ; 21 import javax.faces.component.UIComponent; 22 import javax.faces.component.UIViewRoot; 23 import javax.faces.component.ValueHolder; 24 import javax.faces.context.FacesContext; 25 import javax.faces.context.ResponseWriter; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.struts.util.ResponseUtils; 29 30 31 37 38 public class WriteRenderer extends AbstractRenderer { 39 40 41 43 44 47 private static Log log = LogFactory.getLog(WriteRenderer.class); 48 49 50 52 53 63 public void encodeEnd(FacesContext context, UIComponent component) 64 throws IOException { 65 66 if ((context == null) || (component == null)) { 67 throw new NullPointerException (); 68 } 69 70 ResponseWriter writer = context.getResponseWriter(); 71 String id = component.getId(); 72 if ((id != null) && id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) { 73 id = null; 74 } 75 String style = 76 (String ) component.getAttributes().get("style"); 77 String styleClass = 78 (String ) component.getAttributes().get("styleClass"); 79 if (log.isTraceEnabled()) { 80 log.trace("id='" + id + "', style='" + style + "', styleClass='" + 81 styleClass + "'"); 82 } 83 if ((id != null) || (style != null) || (styleClass != null)) { 84 writer.startElement("span", component); 85 if (id != null) { 86 writer.writeAttribute("id", component.getClientId(context), 87 "id"); 88 } 89 if (style != null) { 90 writer.writeAttribute("style", style, "style"); 91 } 92 if (styleClass != null) { 93 writer.writeAttribute("class", styleClass, "styleClass"); 94 } 95 writer.writeText("", null); 96 } 97 String text = getText(context, component); 98 if (log.isTraceEnabled()) { 99 log.trace("encodeEnd(" + component.getClientId(context) + 100 "," + text + ")"); 101 } 102 writer.write(text); 103 if ((id != null) || (style != null) || (styleClass != null)) { 104 writer.endElement("span"); 105 } 106 107 } 108 109 110 112 113 120 protected String getText(FacesContext context, UIComponent component) { 121 122 String text = getAsString(context, component, 123 ((ValueHolder) component).getValue()); 124 Boolean filter = (Boolean ) component.getAttributes().get("filter"); 125 if (filter == null) { 126 filter = Boolean.FALSE; 127 } 128 if (filter.booleanValue()) { 129 return (ResponseUtils.filter(text)); 130 } else { 131 return (text); 132 } 133 134 } 135 136 137 } 138 | Popular Tags |