1 16 package org.apache.myfaces.taglib; 17 18 import org.apache.myfaces.renderkit.JSFAttr; 19 import org.apache.myfaces.renderkit.RendererUtils; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import javax.faces.component.UIComponent; 25 import javax.faces.webapp.UIComponentBodyTag; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.BodyContent ; 28 import java.io.IOException ; 29 import java.io.Reader ; 30 31 78 public abstract class UIComponentBodyTagBase 79 extends UIComponentBodyTag 80 { 81 private static final Log log = LogFactory.getLog(UIComponentBodyTagBase.class); 82 83 public int doEndTag() throws JspException 84 { 85 if (log.isWarnEnabled()) 86 { 87 UIComponent component = getComponentInstance(); 88 if (component != null && 89 component.getRendersChildren() && 90 !isBodyContentEmpty()) 91 { 92 log.warn("Component with id '" + component.getClientId(getFacesContext()) + 93 "' (" + getClass().getName() + 94 " tag) and path : "+RendererUtils.getPathToComponent(component)+"renders it's children, but has embedded JSP or HTML code. Use the <f:verbatim> tag for nested HTML. For comments use <%/* */%> style JSP comments instead of <!-- --> style HTML comments." + 95 "\n BodyContent:\n" + getBodyContent().getString().trim()); 96 } 97 } 98 return super.doEndTag(); 99 } 100 101 104 private boolean isBodyContentEmpty() 105 { 106 BodyContent bodyContent = getBodyContent(); 107 if (bodyContent == null) 108 { 109 return true; 110 } 111 try 112 { 113 Reader reader = bodyContent.getReader(); 114 int c; 115 while ((c = reader.read()) != -1) 116 { 117 if (!Character.isWhitespace((char)c)) 118 { 119 return false; 120 } 121 } 122 return true; 123 } 124 catch (IOException e) 125 { 126 log.error("Error inspecting BodyContent", e); 127 return false; 128 } 129 } 130 131 133 private String _forceId; 135 private String _forceIdIndex = "true"; 136 137 private String _value; 139 private String _converter; 140 142 protected void setProperties(UIComponent component) 143 { 144 super.setProperties(component); 145 146 setBooleanProperty(component, JSFAttr.FORCE_ID_ATTR, _forceId); 147 setBooleanProperty(component, JSFAttr.FORCE_ID_INDEX_ATTR, _forceIdIndex); 148 149 151 setValueProperty(component, _value); 152 setConverterProperty(component, _converter); 153 } 154 155 162 public void setForceId(String aForceId) 163 { 164 _forceId = aForceId; 165 } 166 167 173 public void setForceIdIndex(String aForceIdIndex) 174 { 175 _forceIdIndex = aForceIdIndex; 176 } 177 178 public void setValue(String value) 179 { 180 _value = value; 181 } 182 183 public void setConverter(String converter) 184 { 185 _converter = converter; 186 } 187 188 189 190 192 protected void setIntegerProperty(UIComponent component, String propName, String value) 193 { 194 UIComponentTagUtils.setIntegerProperty(getFacesContext(), component, propName, value); 195 } 196 197 protected void setStringProperty(UIComponent component, String propName, String value) 198 { 199 UIComponentTagUtils.setStringProperty(getFacesContext(), component, propName, value); 200 } 201 202 protected void setBooleanProperty(UIComponent component, String propName, String value) 203 { 204 UIComponentTagUtils.setBooleanProperty(getFacesContext(), component, propName, value); 205 } 206 207 protected void setValueProperty(UIComponent component, String value) 208 { 209 UIComponentTagUtils.setValueProperty(getFacesContext(), component, value); 210 } 211 212 private void setConverterProperty(UIComponent component, String value) 213 { 214 UIComponentTagUtils.setConverterProperty(getFacesContext(), component, value); 215 } 216 217 protected void setValidatorProperty(UIComponent component, String value) 218 { 219 UIComponentTagUtils.setValidatorProperty(getFacesContext(), component, value); 220 } 221 222 protected void setActionProperty(UIComponent component, String action) 223 { 224 UIComponentTagUtils.setActionProperty(getFacesContext(), component, action); 225 } 226 227 protected void setActionListenerProperty(UIComponent component, String actionListener) 228 { 229 UIComponentTagUtils.setActionListenerProperty(getFacesContext(), component, actionListener); 230 } 231 232 protected void setValueChangedListenerProperty(UIComponent component, String valueChangedListener) 233 { 234 UIComponentTagUtils.setValueChangedListenerProperty(getFacesContext(), component, valueChangedListener); 235 } 236 237 protected void setValueBinding(UIComponent component, 238 String propName, 239 String value) 240 { 241 UIComponentTagUtils.setValueBinding(getFacesContext(), component, propName, value); 242 } 243 244 } 245 | Popular Tags |