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