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.AcceleratorComponent;
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 AcceleratorTag extends CameliaTag implements Tag {
17  
18  
19  	private static final Log LOG=LogFactory.getLog(AcceleratorTag.class);
20  
21  	private ValueExpression keyPressListeners;
22  	private ValueExpression validationListeners;
23  	private ValueExpression forValue;
24  	private ValueExpression forItemValue;
25  	private ValueExpression keyBinding;
26  	private ValueExpression ignoreEditableComponent;
27  	private ValueExpression actionListeners;
28  	private ValueExpression action;
29  	private ValueExpression immediate;
30  	private ValueExpression value;
31  	public String getComponentType() {
32  		return AcceleratorComponent.COMPONENT_TYPE;
33  	}
34  
35  	public final void setKeyPressListener(ValueExpression keyPressListeners) {
36  		this.keyPressListeners = keyPressListeners;
37  	}
38  
39  	public final void setValidationListener(ValueExpression validationListeners) {
40  		this.validationListeners = validationListeners;
41  	}
42  
43  	public final void setFor(ValueExpression forValue) {
44  		this.forValue = forValue;
45  	}
46  
47  	public final void setForItemValue(ValueExpression forItemValue) {
48  		this.forItemValue = forItemValue;
49  	}
50  
51  	public final void setKeyBinding(ValueExpression keyBinding) {
52  		this.keyBinding = keyBinding;
53  	}
54  
55  	public final void setIgnoreEditableComponent(ValueExpression ignoreEditableComponent) {
56  		this.ignoreEditableComponent = ignoreEditableComponent;
57  	}
58  
59  	public final void setAction(ValueExpression action) {
60  		this.action=action;
61  	}
62  
63  	public final void setActionListener(ValueExpression listeners) {
64  		this.actionListeners = listeners;
65  	}
66  
67  	public final void setImmediate(ValueExpression immediate) {
68  		this.immediate = immediate;
69  	}
70  
71  	public final void setValue(ValueExpression value) {
72  		this.value = value;
73  	}
74  
75  	protected void setProperties(UIComponent uiComponent) {
76  		if (LOG.isDebugEnabled()) {
77  			if (AcceleratorComponent.COMPONENT_TYPE==getComponentType()) {
78  				LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
79  			}
80  			LOG.debug("  forValue='"+forValue+"'");
81  			LOG.debug("  forItemValue='"+forItemValue+"'");
82  			LOG.debug("  keyBinding='"+keyBinding+"'");
83  			LOG.debug("  ignoreEditableComponent='"+ignoreEditableComponent+"'");
84  			LOG.debug("  action='"+action+"'");
85  			LOG.debug("  actionListeners='"+actionListeners+"'");
86  		}
87  		if ((uiComponent instanceof AcceleratorComponent)==false) {
88  			if (uiComponent instanceof UIViewRoot) {
89  				throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
90  			}
91  			throw new IllegalStateException("Component specified by tag is not instanceof of 'AcceleratorComponent'.");
92  		}
93  
94  		super.setProperties(uiComponent);
95  
96  		AcceleratorComponent component = (AcceleratorComponent) uiComponent;
97  		FacesContext facesContext = getFacesContext();
98  
99  		if (keyPressListeners != null) {
100 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.KEY_PRESS_LISTENER_TYPE, keyPressListeners);
101 		}
102 
103 		if (validationListeners != null) {
104 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.VALIDATION_LISTENER_TYPE, validationListeners);
105 		}
106 
107 		if (forValue != null) {
108 			if (forValue.isLiteralText()==false) {
109 				component.setValueExpression(Properties.FOR, forValue);
110 
111 			} else {
112 				component.setFor(forValue.getExpressionString());
113 			}
114 		}
115 
116 		if (forItemValue != null) {
117 			if (forItemValue.isLiteralText()==false) {
118 				component.setValueExpression(Properties.FOR_ITEM_VALUE, forItemValue);
119 
120 			} else {
121 				component.setForItemValue(forItemValue.getExpressionString());
122 			}
123 		}
124 
125 		if (keyBinding != null) {
126 			if (keyBinding.isLiteralText()==false) {
127 				component.setValueExpression(Properties.KEY_BINDING, keyBinding);
128 
129 			} else {
130 				component.setKeyBinding(keyBinding.getExpressionString());
131 			}
132 		}
133 
134 		if (ignoreEditableComponent != null) {
135 			if (ignoreEditableComponent.isLiteralText()==false) {
136 				component.setValueExpression(Properties.IGNORE_EDITABLE_COMPONENT, ignoreEditableComponent);
137 
138 			} else {
139 				component.setIgnoreEditableComponent(getBool(ignoreEditableComponent.getExpressionString()));
140 			}
141 		}
142 
143 		if (action != null) {
144 			ListenersTools1_2.parseAction(facesContext, component, ListenersTools.KEY_PRESS_LISTENER_TYPE, action);
145 		}
146 
147 		if (actionListeners != null) {
148 			ListenersTools1_2.parseListener(facesContext, component, ListenersTools.KEY_PRESS_LISTENER_TYPE, actionListeners, true);
149 		}
150 
151 		if (immediate != null) {
152 			if (immediate.isLiteralText()==false) {
153 				component.setValueExpression(Properties.IMMEDIATE, immediate);
154 
155 			} else {
156 				component.setImmediate(getBool(immediate.getExpressionString()));
157 			}
158 		}
159 
160 		if (value != null) {
161 			if (value.isLiteralText()==false) {
162 				component.setValueExpression(Properties.VALUE, value);
163 
164 			} else {
165 				component.setValue(value.getExpressionString());
166 			}
167 		}
168 	}
169 
170 	public void release() {
171 		keyPressListeners = null;
172 		validationListeners = null;
173 		forValue = null;
174 		forItemValue = null;
175 		keyBinding = null;
176 		ignoreEditableComponent = null;
177 		action = null;
178 		actionListeners = null;
179 		immediate = null;
180 		value = null;
181 
182 		super.release();
183 	}
184 
185 }