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 @BeanTag(name = "groupValidationMessages-bean", parent = "Uif-GroupValidationMessages")
45 public class GroupValidationMessages extends ValidationMessages {
46 private static final long serialVersionUID = -5389990220206079052L;
47
48 private boolean displayFieldLabelWithMessages;
49 private boolean collapseAdditionalFieldLinkMessages;
50 private boolean displayHeaderMessageSummary;
51
52 private static final String SECTION_TOKEN = "s$";
53 private static final String FIELDGROUP_TOKEN = "f$";
54 private static final String TABLE_COLLECTION_TOKEN = "c$";
55
56 @Override
57
58
59
60
61
62
63
64
65
66
67 public void generateMessages(boolean reset, View view, Object model, Component parent) {
68 super.generateMessages(reset, view, model, parent);
69
70 Map<String, Object> parentContext = parent.getContext();
71 Object parentContainer = parentContext == null ? null : parentContext
72 .get(UifConstants.ContextVariableNames.PARENT);
73
74 List<? extends Component> items = ((Container) parent).getItems();
75 boolean skipSections = false;
76 boolean isTableCollection = false;
77
78
79 if (parent instanceof CollectionGroup && ((CollectionGroup) parent).getLayoutManager() instanceof StackedLayoutManager) {
80 items = ((StackedLayoutManager) ((CollectionGroup) parent).getLayoutManager()).getStackedGroups();
81 } else if ((parent instanceof CollectionGroup
82 && ((CollectionGroup) parent).getLayoutManager() instanceof TableLayoutManager)
83 || parent instanceof LightTable) {
84
85 items = null;
86 skipSections = true;
87 isTableCollection = true;
88 }
89
90 List<String> sectionIds = new ArrayList<String>();
91 List<String> fieldOrder = new ArrayList<String>();
92 collectIdsFromItems(items, sectionIds, fieldOrder, skipSections);
93
94 boolean pageLevel = false;
95 boolean forceShow = false;
96 boolean showPageSummaryHeader = true;
97 if (parent instanceof PageGroup) {
98 pageLevel = true;
99 forceShow = true;
100 parent.addDataAttribute(UifConstants.DataAttributes.SERVER_MESSAGES, Boolean.toString(
101 GlobalVariables.getMessageMap().hasMessages()));
102 if (this instanceof PageValidationMessages) {
103 showPageSummaryHeader = ((PageValidationMessages) this).isShowPageSummaryHeader();
104 }
105 } else if (parentContainer instanceof FieldGroup) {
106 Map<String, String> parentFieldGroupDataAttributes = ((FieldGroup) parentContainer).getDataAttributes();
107 String role = parentFieldGroupDataAttributes == null ? null : parentFieldGroupDataAttributes
108 .get(UifConstants.DataAttributes.ROLE);
109 if (StringUtils.isNotBlank(role) && role.equals("detailsFieldGroup")){
110 forceShow = false;
111 }
112 else{
113
114 forceShow = true;
115 }
116 }
117
118 boolean hasMessages = false;
119 if (!this.getErrors().isEmpty() || !this.getWarnings().isEmpty() || !this.getInfos().isEmpty()) {
120 hasMessages = true;
121 }
122
123 HashMap<String, Object> validationMessagesDataAttributes = new HashMap<String, Object>();
124
125 Map<String, String> dataDefaults =
126 (Map<String, String>) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryObject(
127 "Uif-GroupValidationMessages-DataDefaults"));
128
129
130
131 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
132 UifConstants.DataAttributes.SUMMARIZE, true);
133 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
134 UifConstants.DataAttributes.DISPLAY_MESSAGES, this.isDisplayMessages());
135 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
136 UifConstants.DataAttributes.COLLAPSE_FIELD_MESSAGES, collapseAdditionalFieldLinkMessages);
137 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
138 UifConstants.DataAttributes.SHOW_PAGE_SUMMARY_HEADER, showPageSummaryHeader);
139 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
140 UifConstants.DataAttributes.DISPLAY_LABEL, displayFieldLabelWithMessages);
141 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
142 UifConstants.DataAttributes.DISPLAY_HEADER_SUMMARY, displayHeaderMessageSummary);
143 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
144 UifConstants.DataAttributes.IS_TABLE_COLLECTION, isTableCollection);
145
146
147 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
148 UifConstants.DataAttributes.HAS_OWN_MESSAGES, hasMessages);
149 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
150 UifConstants.DataAttributes.PAGE_LEVEL, pageLevel);
151 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
152 UifConstants.DataAttributes.FORCE_SHOW, forceShow);
153
154
155 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
156 UifConstants.DataAttributes.SECTIONS, sectionIds);
157 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
158 UifConstants.DataAttributes.ORDER, fieldOrder);
159
160
161 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
162 UifConstants.DataAttributes.SERVER_ERRORS, ScriptUtils.escapeHtml(this.getErrors()));
163 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
164 UifConstants.DataAttributes.SERVER_WARNINGS, ScriptUtils.escapeHtml(this.getWarnings()));
165 this.addValidationDataSettingsValue(validationMessagesDataAttributes, dataDefaults,
166 UifConstants.DataAttributes.SERVER_INFO, ScriptUtils.escapeHtml(this.getInfos()));
167
168 if (!validationMessagesDataAttributes.isEmpty()){
169 parent.addDataAttribute(UifConstants.DataAttributes.VALIDATION_MESSAGES, ScriptUtils.translateValue(
170 validationMessagesDataAttributes));
171 }
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 protected void collectIdsFromItems(List<? extends Component> items, List<String> sectionIds, List<String> order,
189 boolean skipSections) {
190
191 if (items != null) {
192 for (Component component : items) {
193 String id = component.getId().replace("@id@", "");
194 if (component instanceof Container || component instanceof FieldGroup) {
195 if (component instanceof FieldGroup) {
196 if (!skipSections &&
197 ((FieldGroup) component).getFieldLabel().isRender() &&
198 !((FieldGroup) component).getFieldLabel().isHidden() &&
199 (StringUtils.isNotEmpty(((FieldGroup) component).getLabel()) || StringUtils.isNotEmpty(
200 ((FieldGroup) component).getFieldLabel().getLabelText()))) {
201 sectionIds.add(id);
202 order.add(FIELDGROUP_TOKEN + id);
203 continue;
204 } else {
205 component = ((FieldGroup) component).getGroup();
206 if (component == null) {
207 continue;
208 }
209 }
210 }
211
212 id = component.getId().replace("@id@", "");
213
214 if (!skipSections
215 && ((Container) component).getHeader() != null
216 && ((Container) component).getHeader().isRender()
217 && (StringUtils.isNotBlank(((Container) component).getHeader().getHeaderText()) || StringUtils
218 .isNotBlank(component.getTitle()))) {
219 sectionIds.add(id);
220 order.add(SECTION_TOKEN + id);
221 } else if ((component instanceof CollectionGroup
222 && ((CollectionGroup) component).getLayoutManager() instanceof TableLayoutManager)
223 || component instanceof LightTable){
224 order.add(TABLE_COLLECTION_TOKEN + id);
225 } else {
226 collectIdsFromItems(((Container) component).getItems(), sectionIds, order, skipSections);
227 }
228 } else if (component instanceof InputField) {
229 order.add(id);
230 }
231 }
232 }
233 }
234
235
236
237
238
239
240
241
242
243 @BeanTagAttribute(name = "displayFieldLabelWithMessages")
244 public boolean isDisplayFieldLabelWithMessages() {
245 return this.displayFieldLabelWithMessages;
246 }
247
248
249
250
251
252
253
254
255
256 public void setDisplayFieldLabelWithMessages(boolean displayFieldLabelWithMessages) {
257 this.displayFieldLabelWithMessages = displayFieldLabelWithMessages;
258 }
259
260
261
262
263
264
265
266
267
268
269 @BeanTagAttribute(name = "collapseAdditionalFieldLinkMessages")
270 public boolean isCollapseAdditionalFieldLinkMessages() {
271 return collapseAdditionalFieldLinkMessages;
272 }
273
274
275
276
277
278
279 public void setCollapseAdditionalFieldLinkMessages(boolean collapseAdditionalFieldLinkMessages) {
280 this.collapseAdditionalFieldLinkMessages = collapseAdditionalFieldLinkMessages;
281 }
282
283
284
285
286
287
288
289 @BeanTagAttribute(name = "displayHeaderMessageSummary")
290 public boolean isDisplayHeaderMessageSummary() {
291 return displayHeaderMessageSummary;
292 }
293
294
295
296
297
298
299 public void setDisplayHeaderMessageSummary(boolean displayHeaderMessageSummary) {
300 this.displayHeaderMessageSummary = displayHeaderMessageSummary;
301 }
302 }