1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.control;
17
18 import org.apache.commons.lang.ObjectUtils;
19 import org.kuali.rice.core.api.util.AbstractKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.container.Container;
25 import org.kuali.rice.krad.uif.element.Message;
26 import org.kuali.rice.krad.uif.field.InputField;
27 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
28 import org.kuali.rice.krad.uif.util.ComponentFactory;
29 import org.kuali.rice.krad.uif.util.ComponentUtils;
30 import org.kuali.rice.krad.uif.util.KeyMessage;
31 import org.kuali.rice.krad.uif.util.LifecycleElement;
32 import org.kuali.rice.krad.uif.util.UifKeyValueLocation;
33 import org.kuali.rice.krad.uif.util.UifOptionGroupLabel;
34 import org.kuali.rice.krad.uif.util.UrlInfo;
35 import org.kuali.rice.krad.uif.view.ExpressionEvaluator;
36 import org.kuali.rice.krad.uif.view.View;
37
38 import java.util.ArrayList;
39 import java.util.List;
40
41
42
43
44
45
46 public abstract class MultiValueControlBase extends ControlBase implements MultiValueControl {
47 private static final long serialVersionUID = -8691367056245775455L;
48
49 private List<KeyValue> options;
50 private List<KeyMessage> richOptions;
51 private List<Component> inlineComponents;
52
53 private List<Message> internalMessageComponents;
54
55 private boolean locationSelect = false;
56
57 public MultiValueControlBase() {
58 super();
59 }
60
61
62
63
64
65
66 @Override
67 public void performApplyModel(Object model, LifecycleElement parent) {
68 super.performApplyModel(model, parent);
69 getStyleClassesAsString();
70 if (options != null && richOptions == null) {
71 richOptions = new ArrayList<KeyMessage>();
72 internalMessageComponents = new ArrayList<Message>();
73
74 for (KeyValue option : options) {
75
76
77 if (option instanceof UifOptionGroupLabel) {
78 continue;
79 }
80
81 Message message = ComponentFactory.getMessage();
82
83 String key = option.getKey();
84 if (key.contains(UifConstants.EL_PLACEHOLDER_PREFIX)) {
85 key = ViewLifecycle.getExpressionEvaluator().evaluateExpression(this.getContext(), key).toString();
86 }
87
88 String value = option.getValue();
89 if (value.contains(UifConstants.EL_PLACEHOLDER_PREFIX)) {
90 value = ViewLifecycle.getExpressionEvaluator().evaluateExpression(this.getContext(), value).toString();
91 }
92
93 message.setMessageText(value);
94 message.setInlineComponents(inlineComponents);
95 message.setRenderWrapperTag(false);
96
97
98 if(AbstractKeyValue.class.isAssignableFrom(option.getClass()) && ((AbstractKeyValue)option).isDisabled()) {
99 richOptions.add(new KeyMessage(key, value, message, ((AbstractKeyValue)option).isDisabled()));
100 } else {
101 richOptions.add(new KeyMessage(key, value, message));
102 }
103
104 internalMessageComponents.add(message);
105 }
106 }
107 }
108
109
110
111
112
113
114 @Override
115 public void performFinalize(Object model, LifecycleElement parent) {
116 super.performFinalize(model, parent);
117
118 View view = ViewLifecycle.getView();
119 ExpressionEvaluator expressionEvaluator = ViewLifecycle.getExpressionEvaluator();
120
121 if (options != null && !options.isEmpty()) {
122 for (KeyValue option : options) {
123 if (option instanceof UifKeyValueLocation) {
124 locationSelect = true;
125
126 UrlInfo url = ((UifKeyValueLocation) option).getLocation();
127
128 ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(url, false);
129 expressionEvaluator.evaluateExpressionsOnConfigurable(view, url, view.getContext());
130 }
131 }
132 }
133
134 if (richOptions == null || richOptions.isEmpty()) {
135 return;
136 }
137
138
139
140 for (KeyMessage richOption : richOptions) {
141 List<Component> components = richOption.getMessage().getMessageComponentStructure();
142
143 if (components != null && !components.isEmpty()) {
144 for (Component c : components) {
145 if (c instanceof Container || c instanceof InputField) {
146 c.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId());
147 }
148 }
149 }
150 }
151
152 }
153
154
155
156
157 @BeanTagAttribute
158 public List<KeyValue> getOptions() {
159 return this.options;
160 }
161
162
163
164
165 public void setOptions(List<KeyValue> options) {
166 this.options = options;
167 }
168
169
170
171
172
173
174
175 @BeanTagAttribute
176 public List<Component> getInlineComponents() {
177 return inlineComponents;
178 }
179
180
181
182
183
184
185
186 public void setInlineComponents(List<Component> inlineComponents) {
187 this.inlineComponents = inlineComponents;
188 }
189
190
191
192
193 public List<KeyMessage> getRichOptions() {
194 return richOptions;
195 }
196
197
198
199
200
201
202
203
204
205
206 public void setRichOptions(List<KeyMessage> richOptions) {
207 this.richOptions = richOptions;
208 }
209
210
211
212
213
214
215
216
217 public List<Message> getInternalMessageComponents() {
218 return internalMessageComponents;
219 }
220
221
222
223
224
225
226 public boolean isLocationSelect() {
227 return locationSelect;
228 }
229
230
231
232
233
234
235 protected void setLocationSelect(boolean locationSelect) {
236 this.locationSelect = locationSelect;
237 }
238 }