1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.element;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
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.CollectionGroup;
25 import org.kuali.rice.krad.uif.container.Container;
26 import org.kuali.rice.krad.uif.container.LightTable;
27 import org.kuali.rice.krad.uif.container.PageGroup;
28 import org.kuali.rice.krad.uif.field.FieldGroup;
29 import org.kuali.rice.krad.uif.field.InputField;
30 import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
31 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
32 import org.kuali.rice.krad.uif.util.ScriptUtils;
33 import org.kuali.rice.krad.uif.view.View;
34 import org.kuali.rice.krad.util.GlobalVariables;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41
42
43
44
45
46 @BeanTag(name = "groupValidationMessages", parent = "Uif-GroupValidationMessages")
47 public class GroupValidationMessages extends ValidationMessages {
48
49 private static final long serialVersionUID = -5389990220206079052L;
50
51 private boolean closeable;
52
53 private boolean displayFieldLabelWithMessages;
54 private boolean collapseAdditionalFieldLinkMessages;
55 private boolean displayHeaderMessageSummary;
56
57 private static final String SECTION_TOKEN = "s$";
58 private static final String FIELDGROUP_TOKEN = "f$";
59 private static final String TABLE_COLLECTION_TOKEN = "c$";
60
61
62
63
64 @Override
65 public void generateMessages(View view, Object model, Component parent) {
66 super.generateMessages(view, model, parent);
67
68 addValidationMessageDataAttributes(parent);
69 }
70
71
72
73
74
75
76
77
78
79
80 protected void addValidationMessageDataAttributes(Component parent) {
81 HashMap<String, Object> validationMessagesDataAttributes = new HashMap<String, Object>();
82
83 Map<String, Object> parentContext = parent.getContext();
84 Object parentContainer = parentContext == null ? null : parentContext.get(
85 UifConstants.ContextVariableNames.PARENT);
86
87 List<? extends Component> items = ((Container) parent).getItems();
88 boolean skipSections = false;
89 boolean isTableCollection = false;
90
91
92 if (parent instanceof CollectionGroup && ((CollectionGroup) parent)
93 .getLayoutManager() instanceof StackedLayoutManager) {
94 items = ((StackedLayoutManager) ((CollectionGroup) parent).getLayoutManager()).getStackedGroups();
95 } else if ((parent instanceof CollectionGroup && ((CollectionGroup) parent)
96 .getLayoutManager() instanceof TableLayoutManager) || parent instanceof LightTable) {
97
98 items = null;
99 skipSections = true;
100 isTableCollection = true;
101 }
102
103 List<String> sectionIds = new ArrayList<String>();
104 List<String> fieldOrder = new ArrayList<String>();
105 collectIdsFromItems(items, sectionIds, fieldOrder, skipSections);
106
107 boolean pageLevel = false;
108 boolean forceShow = false;
109 boolean showPageSummaryHeader = true;
110 if (parent instanceof PageGroup) {
111 pageLevel = true;
112 forceShow = true;
113 parent.addDataAttribute(UifConstants.DataAttributes.SERVER_MESSAGES, Boolean.toString(
114 GlobalVariables.getMessageMap().hasMessages() || !GlobalVariables.getAuditErrorMap().isEmpty()));
115 if (this instanceof PageValidationMessages) {
116 showPageSummaryHeader = ((PageValidationMessages) this).isShowPageSummaryHeader();
117 }
118 } else if (parentContainer instanceof FieldGroup) {
119 Map<String, String> parentFieldGroupDataAttributes = ((FieldGroup) parentContainer).getDataAttributes();
120 String role = parentFieldGroupDataAttributes == null ? null : parentFieldGroupDataAttributes.get(
121 UifConstants.DataAttributes.ROLE);
122 if (StringUtils.isNotBlank(role) && role.equals("detailsFieldGroup")) {
123 forceShow = false;
124 } else {
125
126 forceShow = true;
127 }
128 }
129
130 boolean hasMessages = false;
131 if (!this.getErrors().isEmpty() || !this.getWarnings().isEmpty() || !this.getInfos().isEmpty()) {
132 hasMessages = true;
133 }
134
135 Map<String, String> dataDefaults =
136 (Map<String, String>) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryBean(
137 "Uif-GroupValidationMessages-DataDefaults"));
138
139
140
141 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
142 UifConstants.DataAttributes.SUMMARIZE, true);
143 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
144 UifConstants.DataAttributes.DISPLAY_MESSAGES, this.isDisplayMessages());
145 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
146 UifConstants.DataAttributes.CLOSEABLE, this.isCloseable());
147 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
148 UifConstants.DataAttributes.COLLAPSE_FIELD_MESSAGES, collapseAdditionalFieldLinkMessages);
149 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
150 UifConstants.DataAttributes.SHOW_PAGE_SUMMARY_HEADER, showPageSummaryHeader);
151 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
152 UifConstants.DataAttributes.DISPLAY_LABEL, displayFieldLabelWithMessages);
153 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
154 UifConstants.DataAttributes.DISPLAY_HEADER_SUMMARY, displayHeaderMessageSummary);
155 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
156 UifConstants.DataAttributes.IS_TABLE_COLLECTION, isTableCollection);
157
158
159 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
160 UifConstants.DataAttributes.HAS_OWN_MESSAGES, hasMessages);
161 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
162 UifConstants.DataAttributes.PAGE_LEVEL, pageLevel);
163 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
164 UifConstants.DataAttributes.FORCE_SHOW, forceShow);
165
166
167 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
168 UifConstants.DataAttributes.SECTIONS, sectionIds);
169 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
170 UifConstants.DataAttributes.ORDER, fieldOrder);
171
172
173 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
174 UifConstants.DataAttributes.SERVER_ERRORS, ScriptUtils.escapeHtml(this.getErrors()));
175 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
176 UifConstants.DataAttributes.SERVER_WARNINGS, ScriptUtils.escapeHtml(this.getWarnings()));
177 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
178 UifConstants.DataAttributes.SERVER_INFO, ScriptUtils.escapeHtml(this.getInfos()));
179
180 if (!validationMessagesDataAttributes.isEmpty()) {
181 parent.addScriptDataAttribute(UifConstants.DataAttributes.VALIDATION_MESSAGES, ScriptUtils.translateValue(
182 validationMessagesDataAttributes));
183 }
184 }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 protected void collectIdsFromItems(List<? extends Component> items, List<String> sectionIds, List<String> order,
201 boolean skipSections) {
202
203 if (items == null) {
204 return;
205 }
206
207 for (Component component : items) {
208 String id = StringUtils.replace(component.getId(), "@id@", "");
209
210 if (component instanceof FieldGroup) {
211 boolean treatFieldGroupAsSection = ((FieldGroup) component).getFieldLabel().isRender() &&
212 !((FieldGroup) component).getFieldLabel().isHidden() &&
213 (StringUtils.isNotEmpty(((FieldGroup) component).getLabel()) || StringUtils.isNotEmpty(
214 ((FieldGroup) component).getFieldLabel().getLabelText()));
215
216 if (!skipSections && treatFieldGroupAsSection) {
217 sectionIds.add(id);
218
219
220 order.add(FIELDGROUP_TOKEN + id);
221 continue;
222 } else {
223 component = ((FieldGroup) component).getGroup();
224 if (component == null) {
225 continue;
226 }
227 }
228 }
229
230
231 if (component instanceof Container) {
232 id = StringUtils.replace(component.getId(), "@id@", "");
233
234
235 boolean isSection =
236 ((Container) component).getHeader() != null && ((Container) component).getHeader().isRender()
237 && (StringUtils.isNotBlank(((Container) component).getHeader().getHeaderText())
238 || StringUtils.isNotBlank(component.getTitle()));
239
240 if (!skipSections && isSection) {
241 sectionIds.add(id);
242
243
244 order.add(SECTION_TOKEN + id);
245 } else if ((component instanceof CollectionGroup && ((CollectionGroup) component)
246 .getLayoutManager() instanceof TableLayoutManager) || component instanceof LightTable) {
247
248 order.add(TABLE_COLLECTION_TOKEN + id);
249 } else {
250
251 collectIdsFromItems(((Container) component).getItems(), sectionIds, order, skipSections);
252 }
253 } else if (component instanceof InputField) {
254 order.add(id);
255 }
256 }
257 }
258
259
260
261
262
263
264
265 public boolean isCloseable() {
266 return closeable;
267 }
268
269
270
271
272 public void setCloseable(boolean closeable) {
273 this.closeable = closeable;
274 }
275
276
277
278
279
280
281
282
283
284 @BeanTagAttribute
285 public boolean isDisplayFieldLabelWithMessages() {
286 return this.displayFieldLabelWithMessages;
287 }
288
289
290
291
292
293
294
295
296
297 public void setDisplayFieldLabelWithMessages(boolean displayFieldLabelWithMessages) {
298 this.displayFieldLabelWithMessages = displayFieldLabelWithMessages;
299 }
300
301
302
303
304
305
306
307
308
309
310 @BeanTagAttribute
311 public boolean isCollapseAdditionalFieldLinkMessages() {
312 return collapseAdditionalFieldLinkMessages;
313 }
314
315
316
317
318
319
320 public void setCollapseAdditionalFieldLinkMessages(boolean collapseAdditionalFieldLinkMessages) {
321 this.collapseAdditionalFieldLinkMessages = collapseAdditionalFieldLinkMessages;
322 }
323
324
325
326
327
328
329
330 @BeanTagAttribute
331 public boolean isDisplayHeaderMessageSummary() {
332 return displayHeaderMessageSummary;
333 }
334
335
336
337
338 public void setDisplayHeaderMessageSummary(boolean displayHeaderMessageSummary) {
339 this.displayHeaderMessageSummary = displayHeaderMessageSummary;
340 }
341 }