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.uif.UifConstants;
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.container.CollectionGroup;
22 import org.kuali.rice.krad.uif.container.Container;
23 import org.kuali.rice.krad.uif.container.PageGroup;
24 import org.kuali.rice.krad.uif.field.FieldGroup;
25 import org.kuali.rice.krad.uif.field.InputField;
26 import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
27 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
28 import org.kuali.rice.krad.uif.util.ScriptUtils;
29 import org.kuali.rice.krad.uif.view.View;
30 import org.kuali.rice.krad.util.GlobalVariables;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35
36
37
38 public class GroupValidationMessages extends ValidationMessages {
39 private static final long serialVersionUID = -5389990220206079052L;
40
41 private boolean displayFieldLabelWithMessages;
42 private boolean collapseAdditionalFieldLinkMessages;
43
44 private static final String SECTION_TOKEN = "s$";
45 private static final String FIELDGROUP_TOKEN = "f$";
46
47 @Override
48
49
50
51
52
53
54
55
56
57
58 public void generateMessages(boolean reset, View view, Object model, Component parent) {
59 super.generateMessages(reset, view, model, parent);
60
61 Object parentContainer = parent.getContext().get(UifConstants.ContextVariableNames.PARENT);
62
63 List<? extends Component> items = ((Container) parent).getItems();
64 boolean skipSections = false;
65
66
67 if (parent instanceof CollectionGroup) {
68 if (((CollectionGroup) parent).getLayoutManager() instanceof StackedLayoutManager) {
69 items = ((StackedLayoutManager) ((CollectionGroup) parent).getLayoutManager()).getStackedGroups();
70 } else if (((CollectionGroup) parent).getLayoutManager() instanceof TableLayoutManager) {
71 items = ((TableLayoutManager) ((CollectionGroup) parent).getLayoutManager()).getDataFields();
72 skipSections = true;
73 }
74 }
75
76 List<String> sectionIds = new ArrayList<String>();
77 List<String> fieldOrder = new ArrayList<String>();
78 collectIdsFromItems(items, sectionIds, fieldOrder, skipSections);
79
80 boolean pageLevel = false;
81 boolean forceShow = false;
82 if (parent instanceof PageGroup) {
83 pageLevel = true;
84 forceShow = true;
85 parent.addDataAttribute(UifConstants.DataAttributes.SERVER_MESSAGES,
86 Boolean.toString(GlobalVariables.getMessageMap().hasMessages()));
87 } else if (parentContainer instanceof FieldGroup) {
88
89 forceShow = true;
90 }
91
92 boolean hasMessages = false;
93 if(!this.getErrors().isEmpty() || !this.getWarnings().isEmpty() || !this.getInfos().isEmpty()){
94 hasMessages = true;
95 }
96 parent.addDataAttribute(UifConstants.DataAttributes.VALIDATION_MESSAGES, "{"
97 + UifConstants.DataAttributes.SUMMARIZE + ":"
98 + true
99 + ","
100 + UifConstants.DataAttributes.DISPLAY_MESSAGES + ":"
101 + this.isDisplayMessages()
102 + ","
103 + UifConstants.DataAttributes.COLLAPSE_FIELD_MESSAGES + ":"
104 + collapseAdditionalFieldLinkMessages
105 + ","
106 + UifConstants.DataAttributes.DISPLAY_LABEL + ":"
107 + displayFieldLabelWithMessages
108 + ","
109 + UifConstants.DataAttributes.HAS_OWN_MESSAGES + ":"
110 + hasMessages
111 + ","
112 + UifConstants.DataAttributes.PAGE_LEVEL + ":"
113 + pageLevel
114 + ","
115 + UifConstants.DataAttributes.FORCE_SHOW + ":"
116 + forceShow
117 + ","
118 + UifConstants.DataAttributes.SECTIONS + ":"
119 + ScriptUtils.convertStringListToJsArray(sectionIds)
120 + ","
121 + UifConstants.DataAttributes.ORDER + ":"
122 + ScriptUtils.convertStringListToJsArray(fieldOrder)
123 + ","
124 + UifConstants.DataAttributes.SERVER_ERRORS + ":"
125 + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getErrors()))
126 + ","
127 + UifConstants.DataAttributes.SERVER_WARNINGS + ":"
128 + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getWarnings()))
129 + ","
130 + UifConstants.DataAttributes.SERVER_INFO + ":"
131 + ScriptUtils.convertStringListToJsArray(ScriptUtils.escapeHtml(this.getInfos()))
132 + "}");
133 }
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 protected void collectIdsFromItems(List<? extends Component> items, List<String> sectionIds, List<String> order,
150 boolean skipSections) {
151
152 if (items != null) {
153 for (Component c : items) {
154 if (c instanceof Container || c instanceof FieldGroup) {
155 if (c instanceof FieldGroup) {
156 if (!skipSections &&
157 ((FieldGroup) c).getFieldLabel().isRender() &&
158 !((FieldGroup) c).getFieldLabel().isHidden() &&
159 (StringUtils.isNotEmpty(((FieldGroup) c).getLabel()) || StringUtils.isNotEmpty(
160 ((FieldGroup) c).getFieldLabel().getLabelText()))) {
161 sectionIds.add(c.getId());
162 order.add(FIELDGROUP_TOKEN + c.getId());
163 continue;
164 } else {
165 c = ((FieldGroup) c).getGroup();
166 if (c == null) {
167 continue;
168 }
169 }
170 }
171
172
173 if (!skipSections
174 && ((Container) c).getHeader() != null
175 && ((Container) c).getHeader().isRender()
176 && (StringUtils.isNotBlank(((Container) c).getHeader().getHeaderText()) || StringUtils
177 .isNotBlank(c.getTitle()))) {
178 sectionIds.add(c.getId());
179 order.add(SECTION_TOKEN + c.getId());
180 } else {
181 collectIdsFromItems(((Container) c).getItems(), sectionIds, order, skipSections);
182 }
183 } else if (c instanceof InputField) {
184 order.add(c.getId());
185 }
186 }
187 }
188 }
189
190
191
192
193
194
195
196
197
198 public boolean isDisplayFieldLabelWithMessages() {
199 return this.displayFieldLabelWithMessages;
200 }
201
202
203
204
205
206
207
208
209
210 public void setDisplayFieldLabelWithMessages(boolean displayFieldLabelWithMessages) {
211 this.displayFieldLabelWithMessages = displayFieldLabelWithMessages;
212 }
213
214
215
216
217
218
219
220
221
222
223 public boolean isCollapseAdditionalFieldLinkMessages() {
224 return collapseAdditionalFieldLinkMessages;
225 }
226
227
228
229
230
231
232 public void setCollapseAdditionalFieldLinkMessages(boolean collapseAdditionalFieldLinkMessages) {
233 this.collapseAdditionalFieldLinkMessages = collapseAdditionalFieldLinkMessages;
234 }
235 }