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 javax.servlet.jsp.tagext.Tag;
10  import org.apache.commons.logging.LogFactory;
11  import org.rcfaces.core.component.ComboComponent;
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 ComboTag extends AbstractInputTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(ComboTag.class);
20  
21  	private ValueExpression selectionListeners;
22  	private ValueExpression required;
23  	private ValueExpression focusStyleClass;
24  	private ValueExpression errorStyleClass;
25  	private ValueExpression fatalStyleClass;
26  	private ValueExpression infoStyleClass;
27  	private ValueExpression warnStyleClass;
28  	private ValueExpression filterProperties;
29  	public String getComponentType() {
30  		return ComboComponent.COMPONENT_TYPE;
31  	}
32  
33  	public final void setSelectionListener(ValueExpression selectionListeners) {
34  		this.selectionListeners = selectionListeners;
35  	}
36  
37  	public final void setRequired(ValueExpression required) {
38  		this.required = required;
39  	}
40  
41  	public final void setFocusStyleClass(ValueExpression focusStyleClass) {
42  		this.focusStyleClass = focusStyleClass;
43  	}
44  
45  	public final void setErrorStyleClass(ValueExpression errorStyleClass) {
46  		this.errorStyleClass = errorStyleClass;
47  	}
48  
49  	public final void setFatalStyleClass(ValueExpression fatalStyleClass) {
50  		this.fatalStyleClass = fatalStyleClass;
51  	}
52  
53  	public final void setInfoStyleClass(ValueExpression infoStyleClass) {
54  		this.infoStyleClass = infoStyleClass;
55  	}
56  
57  	public final void setWarnStyleClass(ValueExpression warnStyleClass) {
58  		this.warnStyleClass = warnStyleClass;
59  	}
60  
61  	public final void setFilterProperties(ValueExpression filterProperties) {
62  		this.filterProperties = filterProperties;
63  	}
64  
65  	protected void setProperties(UIComponent uiComponent) {
66  		if (LOG.isDebugEnabled()) {
67  			if (ComboComponent.COMPONENT_TYPE==getComponentType()) {
68  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
69  			}
70  			LOG.debug("  required='"+required+"'");
71  			LOG.debug("  focusStyleClass='"+focusStyleClass+"'");
72  			LOG.debug("  errorStyleClass='"+errorStyleClass+"'");
73  			LOG.debug("  fatalStyleClass='"+fatalStyleClass+"'");
74  			LOG.debug("  infoStyleClass='"+infoStyleClass+"'");
75  			LOG.debug("  warnStyleClass='"+warnStyleClass+"'");
76  			LOG.debug("  filterProperties='"+filterProperties+"'");
77  		}
78  		if ((uiComponent instanceof ComboComponent)==false) {
79  			if (uiComponent instanceof UIViewRoot) {
80  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
81  			}
82  			throw new IllegalStateException("Component specified by tag is not instanceof of 'ComboComponent'.");
83  		}
84  
85  		super.setProperties(uiComponent);
86  
87  		ComboComponent component = (ComboComponent) uiComponent;
88  		FacesContext facesContext = getFacesContext();
89  
90  		if (selectionListeners != null) {
91  			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SELECTION_LISTENER_TYPE, selectionListeners);
92  		}
93  
94  		if (required != null) {
95  			if (required.isLiteralText()==false) {
96  				component.setValueExpression(Properties.REQUIRED, required);
97  
98  			} else {
99  				component.setRequired(getBool(required.getExpressionString()));
100 			}
101 		}
102 
103 		if (focusStyleClass != null) {
104 			if (focusStyleClass.isLiteralText()==false) {
105 				component.setValueExpression(Properties.FOCUS_STYLE_CLASS, focusStyleClass);
106 
107 			} else {
108 				component.setFocusStyleClass(focusStyleClass.getExpressionString());
109 			}
110 		}
111 
112 		if (errorStyleClass != null) {
113 			if (errorStyleClass.isLiteralText()==false) {
114 				component.setValueExpression(Properties.ERROR_STYLE_CLASS, errorStyleClass);
115 
116 			} else {
117 				component.setErrorStyleClass(errorStyleClass.getExpressionString());
118 			}
119 		}
120 
121 		if (fatalStyleClass != null) {
122 			if (fatalStyleClass.isLiteralText()==false) {
123 				component.setValueExpression(Properties.FATAL_STYLE_CLASS, fatalStyleClass);
124 
125 			} else {
126 				component.setFatalStyleClass(fatalStyleClass.getExpressionString());
127 			}
128 		}
129 
130 		if (infoStyleClass != null) {
131 			if (infoStyleClass.isLiteralText()==false) {
132 				component.setValueExpression(Properties.INFO_STYLE_CLASS, infoStyleClass);
133 
134 			} else {
135 				component.setInfoStyleClass(infoStyleClass.getExpressionString());
136 			}
137 		}
138 
139 		if (warnStyleClass != null) {
140 			if (warnStyleClass.isLiteralText()==false) {
141 				component.setValueExpression(Properties.WARN_STYLE_CLASS, warnStyleClass);
142 
143 			} else {
144 				component.setWarnStyleClass(warnStyleClass.getExpressionString());
145 			}
146 		}
147 
148 		if (filterProperties != null) {
149 			if (filterProperties.isLiteralText()==false) {
150 				component.setValueExpression(Properties.FILTER_PROPERTIES, filterProperties);
151 
152 			} else {
153 				component.setFilterProperties(filterProperties.getExpressionString());
154 			}
155 		}
156 	}
157 
158 	public void release() {
159 		selectionListeners = null;
160 		required = null;
161 		focusStyleClass = null;
162 		errorStyleClass = null;
163 		fatalStyleClass = null;
164 		infoStyleClass = null;
165 		warnStyleClass = null;
166 		filterProperties = null;
167 
168 		super.release();
169 	}
170 
171 }