View Javadoc

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 javax.el.ValueExpression;
7   import javax.faces.component.UIViewRoot;
8   import org.apache.commons.logging.Log;
9   import org.rcfaces.core.component.DateItemComponent;
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 DateItemTag extends SelectItemTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(DateItemTag.class);
20  
21  	private ValueExpression text;
22  	private ValueExpression styleClass;
23  	private ValueExpression menuPopupId;
24  	private ValueExpression literalLocale;
25  	private ValueExpression literalTimeZone;
26  	private ValueExpression date;
27  	public String getComponentType() {
28  		return DateItemComponent.COMPONENT_TYPE;
29  	}
30  
31  	public final void setText(ValueExpression text) {
32  		this.text = text;
33  	}
34  
35  	public final void setStyleClass(ValueExpression styleClass) {
36  		this.styleClass = styleClass;
37  	}
38  
39  	public final void setMenuPopupId(ValueExpression menuPopupId) {
40  		this.menuPopupId = menuPopupId;
41  	}
42  
43  	public final void setLiteralLocale(ValueExpression literalLocale) {
44  		this.literalLocale = literalLocale;
45  	}
46  
47  	public final void setLiteralTimeZone(ValueExpression literalTimeZone) {
48  		this.literalTimeZone = literalTimeZone;
49  	}
50  
51  	public final void setDate(ValueExpression date) {
52  		this.date = date;
53  	}
54  
55  	protected void setProperties(UIComponent uiComponent) {
56  		if (LOG.isDebugEnabled()) {
57  			if (DateItemComponent.COMPONENT_TYPE==getComponentType()) {
58  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
59  			}
60  			LOG.debug("  text='"+text+"'");
61  			LOG.debug("  styleClass='"+styleClass+"'");
62  			LOG.debug("  menuPopupId='"+menuPopupId+"'");
63  			LOG.debug("  literalLocale='"+literalLocale+"'");
64  			LOG.debug("  literalTimeZone='"+literalTimeZone+"'");
65  			LOG.debug("  date='"+date+"'");
66  		}
67  		if ((uiComponent instanceof DateItemComponent)==false) {
68  			if (uiComponent instanceof UIViewRoot) {
69  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
70  			}
71  			throw new IllegalStateException("Component specified by tag is not instanceof of 'DateItemComponent'.");
72  		}
73  
74  		super.setProperties(uiComponent);
75  
76  		DateItemComponent component = (DateItemComponent) uiComponent;
77  		FacesContext facesContext = getFacesContext();
78  
79  		if (text != null) {
80  			if (text.isLiteralText()==false) {
81  				component.setValueExpression(Properties.TEXT, text);
82  
83  			} else {
84  				component.setText(text.getExpressionString());
85  			}
86  		}
87  
88  		if (styleClass != null) {
89  			if (styleClass.isLiteralText()==false) {
90  				component.setValueExpression(Properties.STYLE_CLASS, styleClass);
91  
92  			} else {
93  				component.setStyleClass(styleClass.getExpressionString());
94  			}
95  		}
96  
97  		if (menuPopupId != null) {
98  			if (menuPopupId.isLiteralText()==false) {
99  				component.setValueExpression(Properties.MENU_POPUP_ID, menuPopupId);
100 
101 			} else {
102 				component.setMenuPopupId(menuPopupId.getExpressionString());
103 			}
104 		}
105 
106 		if (literalLocale != null) {
107 			if (literalLocale.isLiteralText()==false) {
108 				component.setValueExpression(Properties.LITERAL_LOCALE, literalLocale);
109 
110 			} else {
111 				component.setLiteralLocale(literalLocale.getExpressionString());
112 			}
113 		}
114 
115 		if (literalTimeZone != null) {
116 			if (literalTimeZone.isLiteralText()==false) {
117 				component.setValueExpression(Properties.LITERAL_TIME_ZONE, literalTimeZone);
118 
119 			} else {
120 				component.setLiteralTimeZone(literalTimeZone.getExpressionString());
121 			}
122 		}
123 
124 		if (date != null) {
125 			if (date.isLiteralText()==false) {
126 				component.setValueExpression(Properties.DATE, date);
127 
128 			} else {
129 				component.setDate(date.getExpressionString());
130 			}
131 		}
132 	}
133 
134 	public void release() {
135 		text = null;
136 		styleClass = null;
137 		menuPopupId = null;
138 		literalLocale = null;
139 		literalTimeZone = null;
140 		date = null;
141 
142 		super.release();
143 	}
144 
145 }