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.uif.component.Component;
22 import org.kuali.rice.krad.uif.container.PageGroup;
23 import org.kuali.rice.krad.uif.lifecycle.LifecycleEventListener;
24 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
25 import org.kuali.rice.krad.uif.util.LifecycleElement;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.MessageMap;
29
30 import java.util.HashSet;
31 import java.util.Set;
32
33
34
35
36
37
38 @BeanTag(name = "pageValidationMessages", parent = "Uif-PageValidationMessages")
39 public class PageValidationMessages extends GroupValidationMessages implements LifecycleEventListener {
40 private static final long serialVersionUID = 6387432156428507958L;
41
42 private boolean showPageSummaryHeader;
43
44
45
46
47 @Override
48 public void generateMessages(View view, Object model, Component parent) {
49 super.generateMessages(view, model, parent);
50
51 ViewLifecycle viewLifecycle = ViewLifecycle.getActiveLifecycle();
52 viewLifecycle.registerLifecycleCompleteListener(view, this);
53 }
54
55
56
57
58
59
60
61 @Override
62 protected void addValidationMessageDataAttributes(Component parent) {
63
64 }
65
66
67
68
69
70
71
72 @Override
73 public void processEvent(ViewLifecycle.LifecycleEvent lifecycleEvent, View view, Object model,
74 LifecycleElement eventElement) {
75 View eventComponent = (View) eventElement;
76 PageGroup currentPage = eventComponent.getCurrentPage();
77
78 Set<String> allPossibleKeys = new HashSet<String>();
79
80 Set<String> renderedPropertyPaths = ViewLifecycle.getViewPostMetadata().getAllRenderedPropertyPaths();
81 if (renderedPropertyPaths != null) {
82 allPossibleKeys.addAll(renderedPropertyPaths);
83 }
84
85 addNestedGroupKeys(allPossibleKeys, currentPage);
86
87 if (getAdditionalKeysToMatch() != null) {
88 allPossibleKeys.addAll(getAdditionalKeysToMatch());
89 }
90
91 if (StringUtils.isNotBlank(currentPage.getId())) {
92 allPossibleKeys.add(currentPage.getId());
93 }
94
95 MessageMap messageMap = GlobalVariables.getMessageMap();
96
97 Set<String> messageKeys = new HashSet<String>();
98
99 messageKeys.addAll(messageMap.getAllPropertiesWithErrors());
100 messageKeys.addAll(messageMap.getAllPropertiesWithWarnings());
101 messageKeys.addAll(messageMap.getAllPropertiesWithInfo());
102
103 messageKeys.removeAll(allPossibleKeys);
104
105 for (String key : messageKeys) {
106 getErrors().addAll(getMessages(view, key, messageMap.getErrorMessagesForProperty(key, true)));
107 getWarnings().addAll(getMessages(view, key, messageMap.getWarningMessagesForProperty(key, true)));
108 getInfos().addAll(getMessages(view, key, messageMap.getInfoMessagesForProperty(key, true)));
109 }
110
111 super.addValidationMessageDataAttributes(currentPage);
112 }
113
114
115
116
117
118
119
120 @BeanTagAttribute
121 public boolean isShowPageSummaryHeader() {
122 return showPageSummaryHeader;
123 }
124
125
126
127
128
129
130 public void setShowPageSummaryHeader(boolean showPageSummaryHeader) {
131 this.showPageSummaryHeader = showPageSummaryHeader;
132 }
133 }