1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared_orchestra.taglib;
20
21 import org.apache.myfaces.shared_orchestra.renderkit.JSFAttr;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.webapp.UIComponentBodyTag;
28 import javax.servlet.jsp.JspException;
29 import javax.servlet.jsp.tagext.BodyContent;
30 import java.io.IOException;
31 import java.io.Reader;
32
33
34
35
36
37 public abstract class UIComponentBodyTagBase
38 extends UIComponentBodyTag
39 {
40 private static final Log log = LogFactory.getLog(UIComponentBodyTagBase.class);
41
42 public int doEndTag() throws JspException
43 {
44 if (log.isWarnEnabled())
45 {
46 UIComponent component = getComponentInstance();
47 if (component != null &&
48 component.getRendersChildren() &&
49 !isBodyContentEmpty())
50 {
51 log.warn("Component with id '" + component.getClientId(getFacesContext()) +
52 "' (" + getClass().getName() +
53 " tag) and path : "+org.apache.myfaces.shared_orchestra.renderkit.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." +
54 "\n BodyContent:\n" + getBodyContent().getString().trim());
55 }
56 }
57 return super.doEndTag();
58 }
59
60
61
62
63 private boolean isBodyContentEmpty()
64 {
65 BodyContent bodyContent = getBodyContent();
66 if (bodyContent == null)
67 {
68 return true;
69 }
70 try
71 {
72 Reader reader = bodyContent.getReader();
73 int c;
74 while ((c = reader.read()) != -1)
75 {
76 if (!Character.isWhitespace((char)c))
77 {
78 return false;
79 }
80 }
81 return true;
82 }
83 catch (IOException e)
84 {
85 log.error("Error inspecting BodyContent", e);
86 return false;
87 }
88 }
89
90
91
92
93 private String _forceId;
94 private String _forceIdIndex = "true";
95
96
97 private String _value;
98 private String _converter;
99
100
101 protected void setProperties(UIComponent component)
102 {
103 super.setProperties(component);
104
105 setBooleanProperty(component, JSFAttr.FORCE_ID_ATTR, _forceId);
106 setBooleanProperty(component, org.apache.myfaces.shared_orchestra.renderkit.JSFAttr.FORCE_ID_INDEX_ATTR, _forceIdIndex);
107
108
109
110 setValueProperty(component, _value);
111 setConverterProperty(component, _converter);
112 }
113
114
115
116
117
118
119
120
121 public void setForceId(String aForceId)
122 {
123 _forceId = aForceId;
124 }
125
126
127
128
129
130
131
132 public void setForceIdIndex(String aForceIdIndex)
133 {
134 _forceIdIndex = aForceIdIndex;
135 }
136
137 public void setValue(String value)
138 {
139 _value = value;
140 }
141
142 public void setConverter(String converter)
143 {
144 _converter = converter;
145 }
146
147
148
149
150
151 protected void setIntegerProperty(UIComponent component, String propName, String value)
152 {
153 UIComponentTagUtils.setIntegerProperty(getFacesContext(), component, propName, value);
154 }
155
156 protected void setStringProperty(UIComponent component, String propName, String value)
157 {
158 UIComponentTagUtils.setStringProperty(getFacesContext(), component, propName, value);
159 }
160
161 protected void setBooleanProperty(UIComponent component, String propName, String value)
162 {
163 UIComponentTagUtils.setBooleanProperty(getFacesContext(), component, propName, value);
164 }
165
166 protected void setValueProperty(UIComponent component, String value)
167 {
168 UIComponentTagUtils.setValueProperty(getFacesContext(), component, value);
169 }
170
171 private void setConverterProperty(UIComponent component, String value)
172 {
173 UIComponentTagUtils.setConverterProperty(getFacesContext(), component, value);
174 }
175
176 protected void setValidatorProperty(UIComponent component, String value)
177 {
178 UIComponentTagUtils.setValidatorProperty(getFacesContext(), component, value);
179 }
180
181 protected void setActionProperty(UIComponent component, String action)
182 {
183 UIComponentTagUtils.setActionProperty(getFacesContext(), component, action);
184 }
185
186 protected void setActionListenerProperty(UIComponent component, String actionListener)
187 {
188 UIComponentTagUtils.setActionListenerProperty(getFacesContext(), component, actionListener);
189 }
190
191 protected void setValueChangedListenerProperty(UIComponent component, String valueChangedListener)
192 {
193 UIComponentTagUtils.setValueChangedListenerProperty(getFacesContext(), component, valueChangedListener);
194 }
195
196 protected void setValueBinding(UIComponent component,
197 String propName,
198 String value)
199 {
200 UIComponentTagUtils.setValueBinding(getFacesContext(), component, propName, value);
201 }
202
203 }