View Javadoc

1   package org.rcfaces.core.component;
2   
3   import org.rcfaces.core.internal.converter.LiteralDateConverter;
4   import org.rcfaces.core.internal.component.Properties;
5   import java.util.Map;
6   import java.util.Collections;
7   import org.apache.commons.logging.LogFactory;
8   import java.util.Date;
9   import org.rcfaces.core.component.capability.IRequiredCapability;
10  import java.util.HashMap;
11  import javax.faces.context.FacesContext;
12  import org.rcfaces.core.internal.component.IDataMapAccessor;
13  import org.rcfaces.core.internal.Constants;
14  import org.rcfaces.core.component.capability.IFocusStyleClassCapability;
15  import org.rcfaces.core.component.AbstractCalendarComponent;
16  import javax.el.ValueExpression;
17  import java.util.HashSet;
18  import org.apache.commons.logging.Log;
19  import java.util.Set;
20  import java.util.Arrays;
21  import org.rcfaces.core.component.capability.IAutoTabCapability;
22  import org.rcfaces.core.internal.manager.IValidationParameters;
23  import org.rcfaces.core.component.capability.IValueChangeEventCapability;
24  import org.rcfaces.core.component.capability.IDateFormatCapability;
25  import org.rcfaces.core.component.capability.ISeverityStyleClassCapability;
26  
27  /**
28   * <p>The dateEntry Component is a specialized <a href="/comps/textEntryComponent.html">textEntry Component</a>. it sports auto-completion related to the validity of the numbers entered as a date.</p>
29   * <p>The dateEntry Component has the following capabilities :
30   * <ul>
31   * <li>PIRequiredCapability</li>
32   * <li>IAutoTabCapability</li>
33   * <li>IValueChangeEventCapability</li>
34   * <li>IFocusStyleClassCapability</li>
35   * <li>ISeverityStyleClassCapability</li>
36   * <li>IDateFormatCapability</li>
37   * <li>IValidationParameters</li>
38   * </ul>
39   * </p>
40   * 
41   * <p>The default <a href="/apidocs/index.html?org/rcfaces/core/component/DateEntryComponent.html">dateEntry</a> renderer is link to the <a href="/jsdocs/index.html?f_dateEntry.html" target="_blank">f_dateEntry</a> javascript class. f_dateEntry extends f_compositeNumEntry, fa_calendarPopup</p>
42   * 
43   * <p> Table of component style classes: </p>
44   * <table border="1" cellpadding="3" cellspacing="0" width="100%">
45   * <tbody>
46   * 
47   * <tr style="text-align:left">
48   * <th  width="33%">Style Name</th>
49   * <th width="50%">Description</th>
50   * </tr>
51   * 
52   * <tr  style="text-align:left">
53   * <td width="33%">f_dateEntry</td>
54   * <td id="ermvsh" width="50%">Defines styles for the wrapper DIV element</td>
55   * </tr>
56   * <tr  style="text-align:left">
57   * <td width="33%">f_dateEntry_dd</td>
58   * <td id="ermvsh" width="50%">Defines styles for day INPUT element.</td>
59   * </tr>
60   * <tr  style="text-align:left">
61   * <td width="33%">f_dateEntry_MM</td>
62   * <td id="ermvsh" width="50%">Defines styles for month INPUT element.</td>
63   * </tr>
64   * <tr  style="text-align:left">
65   * <td width="33%">f_dateEntry_yyyy</td>
66   * <td id="ermvsh" width="50%">Defines styles for years INPUT element.</td>
67   * </tr>
68   * </tbody>
69   * </table>
70   */
71  public class DateEntryComponent extends AbstractCalendarComponent implements 
72  	IRequiredCapability,
73  	IAutoTabCapability,
74  	IValueChangeEventCapability,
75  	IFocusStyleClassCapability,
76  	ISeverityStyleClassCapability,
77  	IDateFormatCapability,
78  	IValidationParameters {
79  
80  	private static final Log LOG = LogFactory.getLog(DateEntryComponent.class);
81  
82  	public static final String COMPONENT_TYPE="org.rcfaces.core.dateEntry";
83  
84  	protected static final Set CAMELIA_ATTRIBUTES=new HashSet(AbstractCalendarComponent.CAMELIA_ATTRIBUTES);
85  	static {
86  		CAMELIA_ATTRIBUTES.addAll(Arrays.asList(new String[] {"autoTab","focusStyleClass","fatalStyleClass","styleClass","showCalendarOnFocus","defaultDate","valueChangeListener","errorStyleClass","warnStyleClass","autoCompletion","infoStyleClass","dateFormat","required"}));
87  	}
88  
89  	public DateEntryComponent() {
90  		setRendererType(COMPONENT_TYPE);
91  	}
92  
93  	public DateEntryComponent(String componentId) {
94  		this();
95  		setId(componentId);
96  	}
97  
98  	public int getValidationParametersCount() {
99  
100 		 
101 		 return getValidationParametersCount(null);
102 		
103 	}
104 
105 	public boolean isClientSideValidationParameter(String name) {
106 
107 
108 		return isClientSideValidationParameter(name, null);
109 		
110 	}
111 
112 	public Map getValidationParametersMap() {
113 
114 
115 		return getValidationParametersMap(null);
116 		
117 	}
118 
119 	public void setValidationParameter(String name, ValueExpression value, boolean client) {
120 
121 
122 		setValidationParameterData(name, value, client);
123 		
124 	}
125 
126 	public String getValidationParameter(String name) {
127 
128 
129 		 return getValidationParameter(name, null);
130 		
131 	}
132 
133 	public Map getClientValidationParametersMap() {
134 
135 
136 		return getClientValidationParametersMap(null);
137 		
138 	}
139 
140 	public String removeValidationParameter(String name) {
141 
142 
143 		FacesContext facesContext=getFacesContext();
144 
145 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", false);
146 		if (dataMapAccessor==null) {
147 			return null;
148 		}
149  
150  		IDataMapAccessor clientMapAccessor=engine.getDataMapAccessor(facesContext, "ClientValidationParameter", false);
151 		if (clientMapAccessor!=null) {
152 			clientMapAccessor.removeData(name, facesContext);
153 		}
154             
155 		return (String)dataMapAccessor.removeData(name, facesContext);
156 		
157 	}
158 
159 	public String setValidationParameter(String name, String value, boolean client) {
160 
161 
162 		return (String)setValidationParameterData(name, value, client);
163 		
164 	}
165 
166 	public void setDefaultDate(String date) {
167 
168 
169 			engine.setProperty(Properties.DEFAULT_DATE, date);
170 		
171 	}
172 
173 	public Date getDefaultDate(FacesContext facesContext) {
174 
175 
176 			Object value=engine.getProperty(Properties.DEFAULT_DATE, facesContext);
177 			if (value instanceof String) {
178 				value=LiteralDateConverter.SINGLETON.getAsObject(facesContext, this, (String)value);
179 			}
180 			
181 			return (Date)value;
182 		
183 	}
184 
185 	public String getValidationParameter(String name, FacesContext facesContext) {
186 
187 
188 		if (facesContext==null) {
189 			facesContext=getFacesContext();
190 		}
191 
192 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", false);
193 		if (dataMapAccessor==null) {
194 			return null;
195 		}
196             
197 		return (String)dataMapAccessor.getData(name, facesContext);
198 		
199 	}
200 
201 	public int getValidationParametersCount(FacesContext facesContext) {
202 
203 
204 		if (facesContext==null) {
205 			facesContext=getFacesContext();
206 		}
207 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", false);
208 		if (dataMapAccessor==null) {
209 			return 0;
210 		}
211 		 
212 		return dataMapAccessor.getDataCount();
213 		
214 	}
215 
216 	public Map getValidationParametersMap(FacesContext facesContext) {
217 
218 
219 		if (facesContext==null) {
220 			facesContext=getFacesContext();
221 		}
222 		
223 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", false);
224 		if (dataMapAccessor==null) {
225 			return Collections.EMPTY_MAP;
226 		}
227             
228 		return dataMapAccessor.getDataMap(facesContext);
229 		
230 	}
231 
232 	public Map getClientValidationParametersMap(FacesContext facesContext) {
233 
234 
235 		if (facesContext==null) {
236 			facesContext=getFacesContext();
237 		}
238 		
239 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", false);
240 		if (dataMapAccessor==null) {
241 			return Collections.EMPTY_MAP;
242 		}
243             
244 		Map map=dataMapAccessor.getDataMap(facesContext);
245 		if (map.isEmpty()) {
246 			return Collections.EMPTY_MAP;
247 		}
248 		
249 		IDataMapAccessor clientMapAccessor=engine.getDataMapAccessor(facesContext, "ClientValidationParameter", false);
250 		if (clientMapAccessor==null) {
251 			if (Constants.READ_ONLY_COLLECTION_LOCK_ENABLED) {
252 				map=Collections.unmodifiableMap(map);
253 			}
254 			return map;
255 		}
256 		
257 		Map client=clientMapAccessor.getDataMap(facesContext);
258 		if (client==null || client.isEmpty()) {
259 		
260 			if (Constants.READ_ONLY_COLLECTION_LOCK_ENABLED) {
261 				map=Collections.unmodifiableMap(map);
262 			}
263 			return map;
264 		}
265 		
266 		Map fmap=new HashMap(map);
267 		if (map.keySet().removeAll(client.keySet())==false) {
268 			if (Constants.READ_ONLY_COLLECTION_LOCK_ENABLED) {
269 				map=Collections.unmodifiableMap(map);
270 			}
271 			return map;
272 		}
273 		
274 		if (fmap.isEmpty()) {
275 			return Collections.EMPTY_MAP;
276 		}
277 		
278 		if (Constants.READ_ONLY_COLLECTION_LOCK_ENABLED) {
279 			fmap=Collections.unmodifiableMap(fmap);
280 		}
281 		
282 		return fmap;
283 		
284 	}
285 
286 	private Object setValidationParameterData(String name, Object value, boolean client) {
287 
288 
289 		FacesContext facesContext=getFacesContext();
290 		IDataMapAccessor dataMapAccessor=engine.getDataMapAccessor(facesContext, "ValidationParameter", true);
291 		if (client) {
292 			// On retire la limitation au niveau client si besoin !
293 			IDataMapAccessor clientMapAccessor=engine.getDataMapAccessor(facesContext, "ClientValidationParameter", false);
294 			if (clientMapAccessor!=null) {
295 				clientMapAccessor.removeData(name, facesContext);
296 			}
297 		} else {
298 			IDataMapAccessor clientMapAccessor=engine.getDataMapAccessor(facesContext, "ClientValidationParameter", true);
299 			clientMapAccessor.setData(name, Boolean.FALSE, facesContext);
300 		}
301             
302 		return dataMapAccessor.setData(name, value, facesContext);
303 		
304 	}
305 
306 	public boolean isClientSideValidationParameter(String name, FacesContext facesContext) {
307 
308 
309 		if (facesContext==null) {
310 			facesContext=getFacesContext();
311 		}
312 		
313 		IDataMapAccessor clientMapAccessor=engine.getDataMapAccessor(facesContext, "ClientValidationParameter", false);
314 		if (clientMapAccessor==null) {
315 			return false;
316 		}
317 		return (clientMapAccessor.getData(name, facesContext)==null);
318 		
319 	}
320 
321 	public boolean isAutoTab() {
322 		return isAutoTab(null);
323 	}
324 
325 	/**
326 	 * See {@link #isAutoTab() isAutoTab()} for more details
327 	 */
328 	public boolean isAutoTab(javax.faces.context.FacesContext facesContext) {
329 		return engine.getBoolProperty(Properties.AUTO_TAB, false, facesContext);
330 	}
331 
332 	/**
333 	 * Returns <code>true</code> if the attribute "autoTab" is set.
334 	 * @return <code>true</code> if the attribute is set.
335 	 */
336 	public final boolean isAutoTabSetted() {
337 		return engine.isPropertySetted(Properties.AUTO_TAB);
338 	}
339 
340 	public void setAutoTab(boolean autoTab) {
341 		engine.setProperty(Properties.AUTO_TAB, autoTab);
342 	}
343 
344 	public final void addValueChangeListener(javax.faces.event.ValueChangeListener listener) {
345 		addFacesListener(listener);
346 	}
347 
348 	public final void removeValueChangeListener(javax.faces.event.ValueChangeListener listener) {
349 		removeFacesListener(listener);
350 	}
351 
352 	public final javax.faces.event.FacesListener [] listValueChangeListeners() {
353 		return getFacesListeners(javax.faces.event.ValueChangeListener.class);
354 	}
355 
356 	public java.lang.String getFocusStyleClass() {
357 		return getFocusStyleClass(null);
358 	}
359 
360 	/**
361 	 * See {@link #getFocusStyleClass() getFocusStyleClass()} for more details
362 	 */
363 	public java.lang.String getFocusStyleClass(javax.faces.context.FacesContext facesContext) {
364 		return engine.getStringProperty(Properties.FOCUS_STYLE_CLASS, facesContext);
365 	}
366 
367 	/**
368 	 * Returns <code>true</code> if the attribute "focusStyleClass" is set.
369 	 * @return <code>true</code> if the attribute is set.
370 	 */
371 	public final boolean isFocusStyleClassSetted() {
372 		return engine.isPropertySetted(Properties.FOCUS_STYLE_CLASS);
373 	}
374 
375 	public void setFocusStyleClass(java.lang.String focusStyleClass) {
376 		engine.setProperty(Properties.FOCUS_STYLE_CLASS, focusStyleClass);
377 	}
378 
379 	public java.lang.String getErrorStyleClass() {
380 		return getErrorStyleClass(null);
381 	}
382 
383 	/**
384 	 * See {@link #getErrorStyleClass() getErrorStyleClass()} for more details
385 	 */
386 	public java.lang.String getErrorStyleClass(javax.faces.context.FacesContext facesContext) {
387 		return engine.getStringProperty(Properties.ERROR_STYLE_CLASS, facesContext);
388 	}
389 
390 	/**
391 	 * Returns <code>true</code> if the attribute "errorStyleClass" is set.
392 	 * @return <code>true</code> if the attribute is set.
393 	 */
394 	public final boolean isErrorStyleClassSetted() {
395 		return engine.isPropertySetted(Properties.ERROR_STYLE_CLASS);
396 	}
397 
398 	public void setErrorStyleClass(java.lang.String errorStyleClass) {
399 		engine.setProperty(Properties.ERROR_STYLE_CLASS, errorStyleClass);
400 	}
401 
402 	public java.lang.String getFatalStyleClass() {
403 		return getFatalStyleClass(null);
404 	}
405 
406 	/**
407 	 * See {@link #getFatalStyleClass() getFatalStyleClass()} for more details
408 	 */
409 	public java.lang.String getFatalStyleClass(javax.faces.context.FacesContext facesContext) {
410 		return engine.getStringProperty(Properties.FATAL_STYLE_CLASS, facesContext);
411 	}
412 
413 	/**
414 	 * Returns <code>true</code> if the attribute "fatalStyleClass" is set.
415 	 * @return <code>true</code> if the attribute is set.
416 	 */
417 	public final boolean isFatalStyleClassSetted() {
418 		return engine.isPropertySetted(Properties.FATAL_STYLE_CLASS);
419 	}
420 
421 	public void setFatalStyleClass(java.lang.String fatalStyleClass) {
422 		engine.setProperty(Properties.FATAL_STYLE_CLASS, fatalStyleClass);
423 	}
424 
425 	public java.lang.String getInfoStyleClass() {
426 		return getInfoStyleClass(null);
427 	}
428 
429 	/**
430 	 * See {@link #getInfoStyleClass() getInfoStyleClass()} for more details
431 	 */
432 	public java.lang.String getInfoStyleClass(javax.faces.context.FacesContext facesContext) {
433 		return engine.getStringProperty(Properties.INFO_STYLE_CLASS, facesContext);
434 	}
435 
436 	/**
437 	 * Returns <code>true</code> if the attribute "infoStyleClass" is set.
438 	 * @return <code>true</code> if the attribute is set.
439 	 */
440 	public final boolean isInfoStyleClassSetted() {
441 		return engine.isPropertySetted(Properties.INFO_STYLE_CLASS);
442 	}
443 
444 	public void setInfoStyleClass(java.lang.String infoStyleClass) {
445 		engine.setProperty(Properties.INFO_STYLE_CLASS, infoStyleClass);
446 	}
447 
448 	public java.lang.String getWarnStyleClass() {
449 		return getWarnStyleClass(null);
450 	}
451 
452 	/**
453 	 * See {@link #getWarnStyleClass() getWarnStyleClass()} for more details
454 	 */
455 	public java.lang.String getWarnStyleClass(javax.faces.context.FacesContext facesContext) {
456 		return engine.getStringProperty(Properties.WARN_STYLE_CLASS, facesContext);
457 	}
458 
459 	/**
460 	 * Returns <code>true</code> if the attribute "warnStyleClass" is set.
461 	 * @return <code>true</code> if the attribute is set.
462 	 */
463 	public final boolean isWarnStyleClassSetted() {
464 		return engine.isPropertySetted(Properties.WARN_STYLE_CLASS);
465 	}
466 
467 	public void setWarnStyleClass(java.lang.String warnStyleClass) {
468 		engine.setProperty(Properties.WARN_STYLE_CLASS, warnStyleClass);
469 	}
470 
471 	public java.lang.String getDateFormat() {
472 		return getDateFormat(null);
473 	}
474 
475 	/**
476 	 * See {@link #getDateFormat() getDateFormat()} for more details
477 	 */
478 	public java.lang.String getDateFormat(javax.faces.context.FacesContext facesContext) {
479 		return engine.getStringProperty(Properties.DATE_FORMAT, facesContext);
480 	}
481 
482 	/**
483 	 * Returns <code>true</code> if the attribute "dateFormat" is set.
484 	 * @return <code>true</code> if the attribute is set.
485 	 */
486 	public final boolean isDateFormatSetted() {
487 		return engine.isPropertySetted(Properties.DATE_FORMAT);
488 	}
489 
490 	public void setDateFormat(java.lang.String dateFormat) {
491 		engine.setProperty(Properties.DATE_FORMAT, dateFormat);
492 	}
493 
494 	/**
495 	 * Returns a boolean value indicating wether the associated <a href="/comps/dateCHooserComponent.html">dateChooser Component</a> should be automatically opened when the component gets the focus.
496 	 * @return true if calendar is to be shown
497 	 */
498 	public boolean isShowCalendarOnFocus() {
499 		return isShowCalendarOnFocus(null);
500 	}
501 
502 	/**
503 	 * Returns a boolean value indicating wether the associated <a href="/comps/dateCHooserComponent.html">dateChooser Component</a> should be automatically opened when the component gets the focus.
504 	 * @return true if calendar is to be shown
505 	 */
506 	public boolean isShowCalendarOnFocus(javax.faces.context.FacesContext facesContext) {
507 		return engine.getBoolProperty(Properties.SHOW_CALENDAR_ON_FOCUS, false, facesContext);
508 	}
509 
510 	/**
511 	 * Sets a boolean value indicating wether the associated <a href="/comps/dateCHooserComponent.html">dateChooser Component</a> should be automatically opened when the component gets the focus.
512 	 * @param showCalendarOnFocus true if calendar is shown
513 	 */
514 	public void setShowCalendarOnFocus(boolean showCalendarOnFocus) {
515 		engine.setProperty(Properties.SHOW_CALENDAR_ON_FOCUS, showCalendarOnFocus);
516 	}
517 
518 	/**
519 	 * Sets a boolean value indicating wether the associated <a href="/comps/dateCHooserComponent.html">dateChooser Component</a> should be automatically opened when the component gets the focus.
520 	 * @param showCalendarOnFocus true if calendar is shown
521 	 */
522 	/**
523 	 * Returns <code>true</code> if the attribute "showCalendarOnFocus" is set.
524 	 * @return <code>true</code> if the attribute is set.
525 	 */
526 	public boolean isShowCalendarOnFocusSetted() {
527 		return engine.isPropertySetted(Properties.SHOW_CALENDAR_ON_FOCUS);
528 	}
529 
530 	/**
531 	 * Returns a boolean value indicating if the component should complete automaticaly the user entry.
532 	 * @return true if the user entry must completed
533 	 */
534 	public boolean isAutoCompletion() {
535 		return isAutoCompletion(null);
536 	}
537 
538 	/**
539 	 * Returns a boolean value indicating if the component should complete automaticaly the user entry.
540 	 * @return true if the user entry must completed
541 	 */
542 	public boolean isAutoCompletion(javax.faces.context.FacesContext facesContext) {
543 		return engine.getBoolProperty(Properties.AUTO_COMPLETION, false, facesContext);
544 	}
545 
546 	/**
547 	 * Sets a boolean value indicating if the component should complete automaticaly the user entry.
548 	 * @param autoCompletion true if the user entry must completed
549 	 */
550 	public void setAutoCompletion(boolean autoCompletion) {
551 		engine.setProperty(Properties.AUTO_COMPLETION, autoCompletion);
552 	}
553 
554 	/**
555 	 * Sets a boolean value indicating if the component should complete automaticaly the user entry.
556 	 * @param autoCompletion true if the user entry must completed
557 	 */
558 	/**
559 	 * Returns <code>true</code> if the attribute "autoCompletion" is set.
560 	 * @return <code>true</code> if the attribute is set.
561 	 */
562 	public boolean isAutoCompletionSetted() {
563 		return engine.isPropertySetted(Properties.AUTO_COMPLETION);
564 	}
565 
566 	/**
567 	 * Returns the date selected by default.
568 	 * @return default date
569 	 */
570 	public java.util.Date getDefaultDate() {
571 		return getDefaultDate(null);
572 	}
573 
574 	/**
575 	 * Sets the date to select by default.
576 	 * @param defaultDate default date
577 	 */
578 	public void setDefaultDate(java.util.Date defaultDate) {
579 		engine.setProperty(Properties.DEFAULT_DATE, defaultDate);
580 	}
581 
582 	/**
583 	 * Sets the date to select by default.
584 	 * @param defaultDate default date
585 	 */
586 	/**
587 	 * Returns <code>true</code> if the attribute "defaultDate" is set.
588 	 * @return <code>true</code> if the attribute is set.
589 	 */
590 	public boolean isDefaultDateSetted() {
591 		return engine.isPropertySetted(Properties.DEFAULT_DATE);
592 	}
593 
594 	protected Set getCameliaFields() {
595 		return CAMELIA_ATTRIBUTES;
596 	}
597 }