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 static org.kuali.rice.krad.uif.UifConstants.ViewPhases.APPLY_MODEL;
19 import static org.kuali.rice.krad.uif.UifConstants.ViewPhases.FINALIZE;
20 import static org.kuali.rice.krad.uif.UifConstants.ViewPhases.INITIALIZE;
21
22 import org.kuali.rice.krad.uif.component.Component;
23 import org.kuali.rice.krad.uif.util.LifecycleElement;
24
25
26
27
28
29
30 public class ViewLifecyclePhaseBuilderBase implements ViewLifecyclePhaseBuilder {
31
32
33
34
35
36
37
38 private static String getPreviousViewPhase(ViewLifecyclePhase phase) {
39 String viewPhase = phase.getViewPhase();
40 if (FINALIZE.equals(viewPhase) && !phase.getElement().isModelApplied()) {
41 return APPLY_MODEL;
42 }
43
44 if (APPLY_MODEL.equals(viewPhase) && !phase.getElement().isInitialized()) {
45 return INITIALIZE;
46 }
47
48 return null;
49 }
50
51
52
53
54 @Override
55 public ViewLifecyclePhase buildPhase(String viewPhase) {
56 ViewLifecyclePhase phase = LifecyclePhaseFactory.buildPhase(viewPhase);
57 phase.prepareView();
58 return finishBuildPhase(phase);
59 }
60
61
62
63
64 @Override
65 public ViewLifecyclePhase buildPhase(String viewPhase, LifecycleElement element, Component parent, String parentPath) {
66 ViewLifecyclePhase phase = LifecyclePhaseFactory.buildPhase(viewPhase);
67 phase.prepareElement(element, parent, parentPath);
68 return finishBuildPhase(phase);
69 }
70
71 private ViewLifecyclePhase finishBuildPhase(ViewLifecyclePhase phase) {
72 String previousViewPhase = getPreviousViewPhase(phase);
73 while (previousViewPhase != null) {
74
75 ViewLifecyclePhase prevPhase = LifecyclePhaseFactory.buildPhase(previousViewPhase);
76 if (phase.getParent() == null) {
77 prevPhase.prepareView();
78 } else {
79 prevPhase.prepareElement(phase.getElement(), phase.getParent(), phase.getParentPath());
80 }
81
82 prevPhase.setNextPhase(phase);
83 phase = prevPhase;
84
85 previousViewPhase = getPreviousViewPhase(phase);
86 }
87
88 return phase;
89 }
90
91 }