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.SuggestTextEntryComponent;
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 SuggestTextEntryTag extends TextEntryTag implements Tag {
17
18
19 private static final Log LOG=LogFactory.getLog(SuggestTextEntryTag.class);
20
21 private ValueExpression filterProperties;
22 private ValueExpression maxResultNumber;
23 private ValueExpression suggestionListeners;
24 private ValueExpression menuListeners;
25 private ValueExpression suggestionDelayMs;
26 private ValueExpression suggestionMinChars;
27 private ValueExpression caseSensitive;
28 private ValueExpression forceProposal;
29 private ValueExpression suggestionValue;
30 private ValueExpression suggestionConverter;
31 private ValueExpression moreResultsMessage;
32 private ValueExpression orderedItems;
33 public String getComponentType() {
34 return SuggestTextEntryComponent.COMPONENT_TYPE;
35 }
36
37 public final void setFilterProperties(ValueExpression filterProperties) {
38 this.filterProperties = filterProperties;
39 }
40
41 public final void setMaxResultNumber(ValueExpression maxResultNumber) {
42 this.maxResultNumber = maxResultNumber;
43 }
44
45 public final void setSuggestionListener(ValueExpression suggestionListeners) {
46 this.suggestionListeners = suggestionListeners;
47 }
48
49 public final void setMenuListener(ValueExpression menuListeners) {
50 this.menuListeners = menuListeners;
51 }
52
53 public final void setSuggestionDelayMs(ValueExpression suggestionDelayMs) {
54 this.suggestionDelayMs = suggestionDelayMs;
55 }
56
57 public final void setSuggestionMinChars(ValueExpression suggestionMinChars) {
58 this.suggestionMinChars = suggestionMinChars;
59 }
60
61 public final void setCaseSensitive(ValueExpression caseSensitive) {
62 this.caseSensitive = caseSensitive;
63 }
64
65 public final void setForceProposal(ValueExpression forceProposal) {
66 this.forceProposal = forceProposal;
67 }
68
69 public final void setSuggestionValue(ValueExpression suggestionValue) {
70 this.suggestionValue = suggestionValue;
71 }
72
73 public final void setSuggestionConverter(ValueExpression suggestionConverter) {
74 this.suggestionConverter = suggestionConverter;
75 }
76
77 public final void setMoreResultsMessage(ValueExpression moreResultsMessage) {
78 this.moreResultsMessage = moreResultsMessage;
79 }
80
81 public final void setOrderedItems(ValueExpression orderedItems) {
82 this.orderedItems = orderedItems;
83 }
84
85 protected void setProperties(UIComponent uiComponent) {
86 if (LOG.isDebugEnabled()) {
87 if (SuggestTextEntryComponent.COMPONENT_TYPE==getComponentType()) {
88 LOG.debug("Component id='"+getId()+"' type='"+getComponentType()+"'.");
89 }
90 LOG.debug(" filterProperties='"+filterProperties+"'");
91 LOG.debug(" maxResultNumber='"+maxResultNumber+"'");
92 LOG.debug(" suggestionDelayMs='"+suggestionDelayMs+"'");
93 LOG.debug(" suggestionMinChars='"+suggestionMinChars+"'");
94 LOG.debug(" caseSensitive='"+caseSensitive+"'");
95 LOG.debug(" forceProposal='"+forceProposal+"'");
96 LOG.debug(" suggestionValue='"+suggestionValue+"'");
97 LOG.debug(" suggestionConverter='"+suggestionConverter+"'");
98 LOG.debug(" moreResultsMessage='"+moreResultsMessage+"'");
99 LOG.debug(" orderedItems='"+orderedItems+"'");
100 }
101 if ((uiComponent instanceof SuggestTextEntryComponent)==false) {
102 if (uiComponent instanceof UIViewRoot) {
103 throw new IllegalStateException("The first component of the page must be a UIViewRoot component !");
104 }
105 throw new IllegalStateException("Component specified by tag is not instanceof of 'SuggestTextEntryComponent'.");
106 }
107
108 super.setProperties(uiComponent);
109
110 SuggestTextEntryComponent component = (SuggestTextEntryComponent) uiComponent;
111 FacesContext facesContext = getFacesContext();
112
113 if (filterProperties != null) {
114 if (filterProperties.isLiteralText()==false) {
115 component.setValueExpression(Properties.FILTER_PROPERTIES, filterProperties);
116
117 } else {
118 component.setFilterProperties(filterProperties.getExpressionString());
119 }
120 }
121
122 if (maxResultNumber != null) {
123 if (maxResultNumber.isLiteralText()==false) {
124 component.setValueExpression(Properties.MAX_RESULT_NUMBER, maxResultNumber);
125
126 } else {
127 component.setMaxResultNumber(getInt(maxResultNumber.getExpressionString()));
128 }
129 }
130
131 if (suggestionListeners != null) {
132 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.SUGGESTION_LISTENER_TYPE, suggestionListeners);
133 }
134
135 if (menuListeners != null) {
136 ListenersTools1_2.parseListener(facesContext, component, ListenersTools.MENU_LISTENER_TYPE, menuListeners);
137 }
138
139 if (suggestionDelayMs != null) {
140 if (suggestionDelayMs.isLiteralText()==false) {
141 component.setValueExpression(Properties.SUGGESTION_DELAY_MS, suggestionDelayMs);
142
143 } else {
144 component.setSuggestionDelayMs(getInt(suggestionDelayMs.getExpressionString()));
145 }
146 }
147
148 if (suggestionMinChars != null) {
149 if (suggestionMinChars.isLiteralText()==false) {
150 component.setValueExpression(Properties.SUGGESTION_MIN_CHARS, suggestionMinChars);
151
152 } else {
153 component.setSuggestionMinChars(getInt(suggestionMinChars.getExpressionString()));
154 }
155 }
156
157 if (caseSensitive != null) {
158 if (caseSensitive.isLiteralText()==false) {
159 component.setValueExpression(Properties.CASE_SENSITIVE, caseSensitive);
160
161 } else {
162 component.setCaseSensitive(getBool(caseSensitive.getExpressionString()));
163 }
164 }
165
166 if (forceProposal != null) {
167 if (forceProposal.isLiteralText()==false) {
168 component.setValueExpression(Properties.FORCE_PROPOSAL, forceProposal);
169
170 } else {
171 component.setForceProposal(getBool(forceProposal.getExpressionString()));
172 }
173 }
174
175 if (suggestionValue != null) {
176 if (suggestionValue.isLiteralText()==false) {
177 component.setValueExpression(Properties.SUGGESTION_VALUE, suggestionValue);
178
179 } else {
180 component.setSuggestionValue(suggestionValue.getExpressionString());
181 }
182 }
183
184 if (suggestionConverter != null) {
185 if (suggestionConverter.isLiteralText()==false) {
186 component.setValueExpression(Properties.SUGGESTION_CONVERTER, suggestionConverter);
187
188 } else {
189 component.setSuggestionConverter(suggestionConverter.getExpressionString());
190 }
191 }
192
193 if (moreResultsMessage != null) {
194 if (moreResultsMessage.isLiteralText()==false) {
195 component.setValueExpression(Properties.MORE_RESULTS_MESSAGE, moreResultsMessage);
196
197 } else {
198 component.setMoreResultsMessage(moreResultsMessage.getExpressionString());
199 }
200 }
201
202 if (orderedItems != null) {
203 if (orderedItems.isLiteralText()==false) {
204 component.setValueExpression(Properties.ORDERED_ITEMS, orderedItems);
205
206 } else {
207 component.setOrderedItems(getBool(orderedItems.getExpressionString()));
208 }
209 }
210 }
211
212 public void release() {
213 filterProperties = null;
214 maxResultNumber = null;
215 suggestionListeners = null;
216 menuListeners = null;
217 suggestionDelayMs = null;
218 suggestionMinChars = null;
219 caseSensitive = null;
220 forceProposal = null;
221 suggestionValue = null;
222 suggestionConverter = null;
223 moreResultsMessage = null;
224 orderedItems = null;
225
226 super.release();
227 }
228
229 }