1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.lookup;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.core.api.util.ConcreteKeyValue;
23 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
24 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
25 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
26 import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint;
27 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
28 import org.kuali.rice.krad.uif.UifConstants;
29 import org.kuali.rice.krad.uif.UifPropertyPaths;
30 import org.kuali.rice.krad.uif.control.CheckboxControl;
31 import org.kuali.rice.krad.uif.control.Control;
32 import org.kuali.rice.krad.uif.control.FilterableLookupCriteriaControl;
33 import org.kuali.rice.krad.uif.control.MultiValueControl;
34 import org.kuali.rice.krad.uif.control.RadioGroupControl;
35 import org.kuali.rice.krad.uif.control.TextAreaControl;
36 import org.kuali.rice.krad.uif.element.Message;
37 import org.kuali.rice.krad.uif.field.InputField;
38 import org.kuali.rice.krad.uif.field.InputFieldBase;
39 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
40 import org.kuali.rice.krad.uif.util.ComponentFactory;
41 import org.kuali.rice.krad.uif.util.ComponentUtils;
42 import org.kuali.rice.krad.uif.util.KeyMessage;
43 import org.kuali.rice.krad.uif.util.LifecycleElement;
44 import org.kuali.rice.krad.util.KRADConstants;
45 import org.kuali.rice.krad.util.KRADPropertyConstants;
46
47
48
49
50
51
52 @BeanTag(name = "lookupCriteria", parent = "Uif-LookupCriteriaInputField")
53 public class LookupInputField extends InputFieldBase {
54 private static final long serialVersionUID = -8294275596836322699L;
55
56 private boolean disableWildcardsAndOperators;
57 private boolean addControlSelectAllOption;
58 private boolean ranged;
59
60 public LookupInputField() {
61 super();
62 }
63
64
65
66
67
68
69
70
71
72
73 @Override
74 public void performFinalize(Object model, LifecycleElement parent) {
75 super.performFinalize(model, parent);
76
77
78 if (addControlSelectAllOption && (getControl() != null) && getControl() instanceof MultiValueControl) {
79 String allOptionText = KRADServiceLocatorWeb.getMessageService().getMessageText(
80 UifConstants.MessageKeys.OPTION_ALL);
81
82 MultiValueControl multiValueControl = (MultiValueControl) getControl();
83 if (multiValueControl.getOptions() != null) {
84 multiValueControl.getOptions().add(0, new ConcreteKeyValue("", allOptionText));
85 }
86
87 if (multiValueControl.getRichOptions() != null) {
88 Message message = ComponentFactory.getMessage();
89 message.setMessageText(allOptionText);
90 message.setRenderWrapperTag(false);
91
92 multiValueControl.getRichOptions().add(0, new KeyMessage("", allOptionText, message));
93 }
94 }
95 }
96
97
98
99
100 @Override
101 protected void addComponentPostMetadata() {
102 super.addComponentPostMetadata();
103
104 Map<String, Map<String, Object>> lookupCriteriaFields = ViewLifecycle.getViewPostMetadata().getLookupCriteria();
105
106 Map<String, Object> criteriaAttributes = new HashMap<String, Object>();
107 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.COMPONENT_ID, this.getId());
108
109 if (this.isDisableWildcardsAndOperators()) {
110 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.DISABLE_WILDCARDS_AND_OPERATORS, true);
111 }
112
113 if (this.getRequired()) {
114 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.REQUIRED, true);
115 }
116
117 if (this.hasSecureValue()) {
118 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.SECURE_VALUE, true);
119 }
120
121 ValidCharactersConstraint validCharactersConstraint = this.getValidCharactersConstraint();
122 if (validCharactersConstraint != null) {
123 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.VALID_CHARACTERS_CONSTRAINT,
124 validCharactersConstraint);
125 }
126
127 lookupCriteriaFields.put(this.getPropertyName(), criteriaAttributes);
128
129 addHiddenComponentPostMetadata(lookupCriteriaFields);
130 }
131
132
133
134
135
136
137 protected void addHiddenComponentPostMetadata(Map<String, Map<String, Object>> lookupCriteriaFields) {
138 for (String hiddenPropertyName: this.getAdditionalHiddenPropertyNames()) {
139 hiddenPropertyName = StringUtils.substringBetween(hiddenPropertyName, UifPropertyPaths.LOOKUP_CRITERIA + "[", "]");
140
141
142 if (!lookupCriteriaFields.containsKey(hiddenPropertyName)) {
143 Map<String, Object> criteriaAttributes = new HashMap<String, Object>();
144 criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.HIDDEN, true);
145 lookupCriteriaFields.put(hiddenPropertyName, criteriaAttributes);
146 }
147 }
148 }
149
150
151
152
153
154
155
156
157
158
159 @Override
160 public void copyFromAttributeDefinition(AttributeDefinition attributeDefinition) {
161
162 if (StringUtils.isEmpty(getLabel())) {
163 setLabel(attributeDefinition.getLabel());
164 }
165
166
167 if (StringUtils.isEmpty(getShortLabel())) {
168 setShortLabel(attributeDefinition.getShortLabel());
169 }
170
171
172 if ((attributeDefinition.getAttributeSecurity() != null) && ((getDataFieldSecurity() == null) || (
173 getDataFieldSecurity().getAttributeSecurity() == null))) {
174 initializeComponentSecurity();
175
176 getDataFieldSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
177 }
178
179
180 if (getOptionsFinder() == null) {
181 setOptionsFinder(attributeDefinition.getOptionsFinder());
182 }
183
184
185 if (getControl() == null) {
186 Control control = convertControlToLookupControl(attributeDefinition);
187 setControl(control);
188 }
189
190
191 setMaxLength(100);
192 if ( attributeDefinition.getMaxLength()!=null && (attributeDefinition.getMaxLength() > 100)) {
193 setMaxLength(attributeDefinition.getMaxLength());
194 }
195
196
197 if (getDefaultValue() == null || (getDefaultValue() instanceof String && StringUtils.isEmpty((String)getDefaultValue()))) {
198 if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
199 setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
200 }
201 }
202 }
203
204
205
206
207
208
209
210
211 protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
212 if (attributeDefinition.getControlField() == null) {
213 return null;
214 }
215
216 Control newControl = null;
217
218
219 if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
220 newControl = (RadioGroupControl) ComponentFactory.getNewComponentInstance(
221 ComponentFactory.CHECKBOX_CONVERTED_RADIO_CONTROL);
222 }
223
224 else if (TextAreaControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
225 newControl = ComponentFactory.getTextControl();
226 } else {
227 newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
228 }
229
230 return newControl;
231 }
232
233
234
235
236
237
238
239 public Map<String, String> filterSearchCriteria(Map<String, String> searchCriteria) {
240 return searchCriteria;
241 }
242
243
244
245
246
247
248
249 @BeanTagAttribute(name = "disableWildcardsAndOperators")
250 public boolean isDisableWildcardsAndOperators() {
251 return this.disableWildcardsAndOperators;
252 }
253
254
255
256
257 public void setDisableWildcardsAndOperators(boolean disableWildcardsAndOperators) {
258 this.disableWildcardsAndOperators = disableWildcardsAndOperators;
259 }
260
261
262
263
264
265
266
267 @BeanTagAttribute(name = "addControlSelectAllOption")
268 public boolean isAddControlSelectAllOption() {
269 return addControlSelectAllOption;
270 }
271
272
273
274
275 public void setAddControlSelectAllOption(boolean addControlSelectAllOption) {
276 this.addControlSelectAllOption = addControlSelectAllOption;
277 }
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293 public boolean isRanged() {
294 return ranged;
295 }
296
297
298
299
300 public void setRanged(boolean ranged) {
301 this.ranged = ranged;
302 }
303 }