1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.container.PageGroup;
23 import org.kuali.rice.krad.uif.service.ViewHelperService;
24 import org.kuali.rice.krad.uif.util.ProcessLogger;
25 import org.kuali.rice.krad.uif.view.View;
26 import org.kuali.rice.krad.uif.view.ViewModel;
27 import org.kuali.rice.krad.web.controller.UifControllerHelper;
28 import org.kuali.rice.krad.web.form.UifFormBase;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40
41 public class ViewLifecycleBuild implements Runnable {
42 private static final Logger LOG = LoggerFactory.getLogger(ViewLifecycleBuild.class);
43
44 private final Map<String, String> parameters;
45 private final Map<String, List<String>> refreshPathMappings;
46
47
48
49
50
51
52
53
54
55 public ViewLifecycleBuild(Map<String, String> parameters, Map<String, List<String>> refreshPathMappings) {
56 this.parameters = parameters;
57 this.refreshPathMappings = refreshPathMappings;
58 }
59
60
61
62
63 @Override
64 public void run() {
65 View view = ViewLifecycle.getView();
66
67 ProcessLogger.trace("begin-view-lifecycle:" + view.getId());
68
69 populateViewRequestParameters();
70
71 runInitializePhase();
72
73 runApplyModelPhase();
74
75 runFinalizePhase();
76
77
78 ((ViewModel) ViewLifecycle.getModel()).getViewsThatNeedDefaultValuesApplied().remove(view.getId());
79
80
81 String growlScript = ViewLifecycle.getHelper().buildGrowlScript();
82 ((ViewModel) ViewLifecycle.getModel()).setGrowlScript(growlScript);
83
84
85 if (ViewLifecycle.isRefreshLifecycle()) {
86 PageGroup page = view.getCurrentPage();
87 page.getValidationMessages().generateMessages(view, ViewLifecycle.getModel(), page);
88 }
89
90 LifecycleRefreshPathBuilder.processLifecycleElements();
91
92 ViewLifecycle.getViewPostMetadata().cleanAfterLifecycle();
93
94 ProcessLogger.trace("finalize:" + view.getId());
95 }
96
97
98
99
100
101 protected void populateViewRequestParameters() {
102 View view = ViewLifecycle.getView();
103 ViewHelperService helper = ViewLifecycle.getHelper();
104 UifFormBase model = (UifFormBase) ViewLifecycle.getModel();
105
106
107
108 Map<String, String> parametersToPopulate = parameters;
109 if (ViewLifecycle.isRefreshLifecycle()) {
110 parametersToPopulate = model.getViewRequestParameters();
111 }
112
113 helper.populateViewFromRequestParameters(parametersToPopulate);
114
115
116 model.setViewRequestParameters(view.getViewRequestParameters());
117 }
118
119
120
121
122
123
124
125 protected void runInitializePhase() {
126 ViewLifecycleProcessor processor = ViewLifecycle.getProcessor();
127
128 View view = ViewLifecycle.getView();
129 ViewHelperService helper = ViewLifecycle.getHelper();
130 UifFormBase model = (UifFormBase) ViewLifecycle.getModel();
131
132 ViewLifecycle.getExpressionEvaluator().initializeEvaluationContext(model);
133
134 if (LOG.isInfoEnabled()) {
135 LOG.info("performing initialize phase for view: " + view.getId());
136 }
137
138 helper.performCustomViewInitialization(model);
139
140 List<String> refreshPaths = null;
141 if (refreshPathMappings != null) {
142 refreshPaths = refreshPathMappings.get(UifConstants.ViewPhases.INITIALIZE);
143 }
144
145 processor.performPhase(LifecyclePhaseFactory.initialize(view, model, "", refreshPaths, null, null));
146
147 ProcessLogger.trace("initialize:" + view.getId());
148 }
149
150
151
152
153
154
155
156 protected void runApplyModelPhase() {
157 ViewLifecycleProcessor processor = ViewLifecycle.getProcessor();
158
159 View view = ViewLifecycle.getView();
160 ViewHelperService helper = ViewLifecycle.getHelper();
161 UifFormBase model = (UifFormBase) ViewLifecycle.getModel();
162
163 if (LOG.isInfoEnabled()) {
164 LOG.info("performing apply model phase for view: " + view.getId());
165 }
166
167
168 if (model.getViewsThatNeedDefaultValuesApplied().contains(view.getId())) {
169 helper.applyDefaultValues(view);
170
171
172 model.getViewsThatNeedDefaultValuesApplied().remove(view.getId());
173 }
174
175
176 helper.retrieveEditModesAndActionFlags();
177
178
179 helper.setViewContext();
180
181 List<String> refreshPaths = null;
182 if (refreshPathMappings != null) {
183 refreshPaths = refreshPathMappings.get(UifConstants.ViewPhases.APPLY_MODEL);
184 }
185
186 processor.performPhase(LifecyclePhaseFactory.applyModel(view, model, "", refreshPaths));
187
188 ProcessLogger.trace("apply-model:" + view.getId());
189 }
190
191
192
193
194
195
196 protected void runFinalizePhase() {
197 ViewLifecycleProcessor processor = ViewLifecycle.getProcessor();
198
199 View view = ViewLifecycle.getView();
200 UifFormBase model = (UifFormBase) ViewLifecycle.getModel();
201
202 if (LOG.isInfoEnabled()) {
203 LOG.info("performing finalize phase for view: " + view.getId());
204 }
205
206 List<String> refreshPaths = null;
207 if (refreshPathMappings != null) {
208 refreshPaths = refreshPathMappings.get(UifConstants.ViewPhases.FINALIZE);
209 }
210
211 processor.performPhase(LifecyclePhaseFactory.finalize(view, model, "", refreshPaths, null));
212 }
213
214 }