1 package org.rcfaces.core.internal.taglib;
2
3 import javax.faces.application.Application;
4 import javax.faces.component.UIComponent;
5 import org.rcfaces.core.internal.component.Properties;
6 import org.rcfaces.core.component.DateChooserComponent;
7 import javax.el.ValueExpression;
8 import javax.faces.component.UIViewRoot;
9 import org.apache.commons.logging.Log;
10 import javax.servlet.jsp.tagext.Tag;
11 import org.apache.commons.logging.LogFactory;
12 import org.rcfaces.core.internal.tools.ListenersTools1_2;
13 import org.rcfaces.core.internal.tools.ListenersTools;
14 import javax.faces.context.FacesContext;
15
16 public class DateChooserTag extends AbstractCalendarTag implements Tag {
17
18
19 private static final Log LOG=LogFactory.getLog(DateChooserTag.class);
20
21 private ValueExpression imageURL;
22 private ValueExpression disabledImageURL;
23 private ValueExpression hoverImageURL;
24 private ValueExpression selectedImageURL;
25 private ValueExpression border;
26 private ValueExpression borderType;
27 private ValueExpression text;
28 private ValueExpression textPosition;
29 private ValueExpression imageHeight;
30 private ValueExpression imageWidth;
31 private ValueExpression valueChangeListeners;
32 private ValueExpression forValue;
33 private ValueExpression calendarLayout;
34 private ValueExpression forValueFormat;
35 private ValueExpression homeDate;
36 private ValueExpression defaultSelectedDate;
37 private ValueExpression homeDateLabel;
38 private ValueExpression popupStyleClass;
39 public String getComponentType() {
40 return DateChooserComponent.COMPONENT_TYPE;
41 }
42
43 public final void setImageURL(ValueExpression imageURL) {
44 this.imageURL = imageURL;
45 }
46
47 public final void setDisabledImageURL(ValueExpression disabledImageURL) {
48 this.disabledImageURL = disabledImageURL;
49 }
50
51 public final void setHoverImageURL(ValueExpression hoverImageURL) {
52 this.hoverImageURL = hoverImageURL;
53 }
54
55 public final void setSelectedImageURL(ValueExpression selectedImageURL) {
56 this.selectedImageURL = selectedImageURL;
57 }
58
59 public final void setBorder(ValueExpression border) {
60 this.border = border;
61 }
62
63 public final void setBorderType(ValueExpression borderType) {
64 this.borderType = borderType;
65 }
66
67 public final void setText(ValueExpression text) {
68 this.text = text;
69 }
70
71 public final void setTextPosition(ValueExpression textPosition) {
72 this.textPosition = textPosition;
73 }
74
75 public final void setImageHeight(ValueExpression imageHeight) {
76 this.imageHeight = imageHeight;
77 }
78
79 public final void setImageWidth(ValueExpression imageWidth) {
80 this.imageWidth = imageWidth;
81 }
82
83 public final void setValueChangeListener(ValueExpression valueChangeListeners) {
84 this.valueChangeListeners = valueChangeListeners;
85 }
86
87 public final void setFor(ValueExpression forValue) {
88 this.forValue = forValue;
89 }
90
91 public final void setCalendarLayout(ValueExpression calendarLayout) {
92 this.calendarLayout = calendarLayout;
93 }
94
95 public final void setForValueFormat(ValueExpression forValueFormat) {
96 this.forValueFormat = forValueFormat;
97 }
98
99 public final void setHomeDate(ValueExpression homeDate) {
100 this.homeDate = homeDate;
101 }
102
103 public final void setDefaultSelectedDate(ValueExpression defaultSelectedDate) {
104 this.defaultSelectedDate = defaultSelectedDate;
105 }
106
107 public final void setHomeDateLabel(ValueExpression homeDateLabel) {
108 this.homeDateLabel = homeDateLabel;
109 }
110
111 public final void setPopupStyleClass(ValueExpression popupStyleClass) {
112 this.popupStyleClass = popupStyleClass;
113 }
114
115 protected void setProperties(UIComponent uiComponent) {
116 if (LOG.isDebugEnabled()) {
117 if (DateChooserComponent.COMPONENT_TYPE==getComponentType()) {
118 LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
119 }
120 LOG.debug(" imageURL='"+imageURL+"'");
121 LOG.debug(" disabledImageURL='"+disabledImageURL+"'");
122 LOG.debug(" hoverImageURL='"+hoverImageURL+"'");
123 LOG.debug(" selectedImageURL='"+selectedImageURL+"'");
124 LOG.debug(" border='"+border+"'");
125 LOG.debug(" borderType='"+borderType+"'");
126 LOG.debug(" text='"+text+"'");
127 LOG.debug(" textPosition='"+textPosition+"'");
128 LOG.debug(" imageHeight='"+imageHeight+"'");
129 LOG.debug(" imageWidth='"+imageWidth+"'");
130 LOG.debug(" forValue='"+forValue+"'");
131 LOG.debug(" calendarLayout='"+calendarLayout+"'");
132 LOG.debug(" forValueFormat='"+forValueFormat+"'");
133 LOG.debug(" homeDate='"+homeDate+"'");
134 LOG.debug(" defaultSelectedDate='"+defaultSelectedDate+"'");
135 LOG.debug(" homeDateLabel='"+homeDateLabel+"'");
136 LOG.debug(" popupStyleClass='"+popupStyleClass+"'");
137 }
138 if ((uiComponent instanceof DateChooserComponent)==false) {
139 if (uiComponent instanceof UIViewRoot) {
140 throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
141 }
142 throw new IllegalStateException("Component specified by tag is not instanceof of 'DateChooserComponent'.");
143 }
144
145 super.setProperties(uiComponent);
146
147 DateChooserComponent component = (DateChooserComponent) uiComponent;
148 FacesContext facesContext = getFacesContext();
149
150 if (imageURL != null) {
151 if (imageURL.isLiteralText()==false) {
152 component.setValueExpression(Properties.IMAGE_URL, imageURL);
153
154 } else {
155 component.setImageURL(imageURL.getExpressionString());
156 }
157 }
158
159 if (disabledImageURL != null) {
160 if (disabledImageURL.isLiteralText()==false) {
161 component.setValueExpression(Properties.DISABLED_IMAGE_URL, disabledImageURL);
162
163 } else {
164 component.setDisabledImageURL(disabledImageURL.getExpressionString());
165 }
166 }
167
168 if (hoverImageURL != null) {
169 if (hoverImageURL.isLiteralText()==false) {
170 component.setValueExpression(Properties.HOVER_IMAGE_URL, hoverImageURL);
171
172 } else {
173 component.setHoverImageURL(hoverImageURL.getExpressionString());
174 }
175 }
176
177 if (selectedImageURL != null) {
178 if (selectedImageURL.isLiteralText()==false) {
179 component.setValueExpression(Properties.SELECTED_IMAGE_URL, selectedImageURL);
180
181 } else {
182 component.setSelectedImageURL(selectedImageURL.getExpressionString());
183 }
184 }
185
186 if (border != null) {
187 if (border.isLiteralText()==false) {
188 component.setValueExpression(Properties.BORDER, border);
189
190 } else {
191 component.setBorder(getBool(border.getExpressionString()));
192 }
193 }
194
195 if (borderType != null) {
196 if (borderType.isLiteralText()==false) {
197 component.setValueExpression(Properties.BORDER_TYPE, borderType);
198
199 } else {
200 component.setBorderType(borderType.getExpressionString());
201 }
202 }
203
204 if (text != null) {
205 if (text.isLiteralText()==false) {
206 component.setValueExpression(Properties.TEXT, text);
207
208 } else {
209 component.setText(text.getExpressionString());
210 }
211 }
212
213 if (textPosition != null) {
214 if (textPosition.isLiteralText()==false) {
215 component.setValueExpression(Properties.TEXT_POSITION, textPosition);
216
217 } else {
218 component.setTextPosition(textPosition.getExpressionString());
219 }
220 }
221
222 if (imageHeight != null) {
223 if (imageHeight.isLiteralText()==false) {
224 component.setValueExpression(Properties.IMAGE_HEIGHT, imageHeight);
225
226 } else {
227 component.setImageHeight(getInt(imageHeight.getExpressionString()));
228 }
229 }
230
231 if (imageWidth != null) {
232 if (imageWidth.isLiteralText()==false) {
233 component.setValueExpression(Properties.IMAGE_WIDTH, imageWidth);
234
235 } else {
236 component.setImageWidth(getInt(imageWidth.getExpressionString()));
237 }
238 }
239
240 if (valueChangeListeners != null) {
241 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.VALUE_CHANGE_LISTENER_TYPE, valueChangeListeners);
242 }
243
244 if (forValue != null) {
245 if (forValue.isLiteralText()==false) {
246 component.setValueExpression(Properties.FOR, forValue);
247
248 } else {
249 component.setFor(forValue.getExpressionString());
250 }
251 }
252
253 if (calendarLayout != null) {
254 if (calendarLayout.isLiteralText()==false) {
255 component.setValueExpression(Properties.CALENDAR_LAYOUT, calendarLayout);
256
257 } else {
258 component.setCalendarLayout(calendarLayout.getExpressionString());
259 }
260 }
261
262 if (forValueFormat != null) {
263 if (forValueFormat.isLiteralText()==false) {
264 component.setValueExpression(Properties.FOR_VALUE_FORMAT, forValueFormat);
265
266 } else {
267 component.setForValueFormat(forValueFormat.getExpressionString());
268 }
269 }
270
271 if (homeDate != null) {
272 if (homeDate.isLiteralText()==false) {
273 component.setValueExpression(Properties.HOME_DATE, homeDate);
274
275 } else {
276 component.setHomeDate(homeDate.getExpressionString());
277 }
278 }
279
280 if (defaultSelectedDate != null) {
281 if (defaultSelectedDate.isLiteralText()==false) {
282 component.setValueExpression(Properties.DEFAULT_SELECTED_DATE, defaultSelectedDate);
283
284 } else {
285 component.setDefaultSelectedDate(defaultSelectedDate.getExpressionString());
286 }
287 }
288
289 if (homeDateLabel != null) {
290 if (homeDateLabel.isLiteralText()==false) {
291 component.setValueExpression(Properties.HOME_DATE_LABEL, homeDateLabel);
292
293 } else {
294 component.setHomeDateLabel(homeDateLabel.getExpressionString());
295 }
296 }
297
298 if (popupStyleClass != null) {
299 if (popupStyleClass.isLiteralText()==false) {
300 component.setValueExpression(Properties.POPUP_STYLE_CLASS, popupStyleClass);
301
302 } else {
303 component.setPopupStyleClass(popupStyleClass.getExpressionString());
304 }
305 }
306 }
307
308 public void release() {
309 imageURL = null;
310 disabledImageURL = null;
311 hoverImageURL = null;
312 selectedImageURL = null;
313 border = null;
314 borderType = null;
315 text = null;
316 textPosition = null;
317 imageHeight = null;
318 imageWidth = null;
319 valueChangeListeners = null;
320 forValue = null;
321 calendarLayout = null;
322 forValueFormat = null;
323 homeDate = null;
324 defaultSelectedDate = null;
325 homeDateLabel = null;
326 popupStyleClass = null;
327
328 super.release();
329 }
330
331 }