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.Queue;
20 import java.util.Set;
21
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.component.Component;
24 import org.kuali.rice.krad.uif.freemarker.RenderComponentTask;
25 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle.LifecycleEvent;
26 import org.kuali.rice.krad.uif.util.LifecycleElement;
27 import org.kuali.rice.krad.uif.util.RecycleUtils;
28
29
30
31
32
33
34
35 public class RenderComponentPhase extends ViewLifecyclePhaseBase {
36
37 private RenderComponentPhase renderParent;
38 private Set<String> pendingChildren;
39
40
41
42
43 @Override
44 protected void recycle() {
45 super.recycle();
46 renderParent = null;
47 pendingChildren = null;
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61 protected void prepare(LifecycleElement element, Object model, String path, List<String> refreshPaths,
62 Component parentComponent, RenderComponentPhase renderParent, Set<String> pendingChildren) {
63 super.prepare(element, model, path, refreshPaths, parentComponent, null);
64
65 this.renderParent = renderParent;
66 this.pendingChildren = pendingChildren;
67 }
68
69
70
71
72
73
74 @Override
75 public String getViewPhase() {
76 return UifConstants.ViewPhases.RENDER;
77 }
78
79
80
81
82
83
84 @Override
85 public String getStartViewStatus() {
86 return UifConstants.ViewStatus.FINAL;
87 }
88
89
90
91
92
93
94 @Override
95 public String getEndViewStatus() {
96 return UifConstants.ViewStatus.RENDERED;
97 }
98
99
100
101
102 @Override
103 public LifecycleEvent getEventToNotify() {
104 return null;
105 }
106
107
108
109
110 @Override
111 protected void verifyCompleted() {
112 if (pendingChildren != null) {
113 ViewLifecycle.reportIllegalState("Render phase is not complete, children are still pending "
114 + pendingChildren + "\n" + this);
115 }
116 }
117
118
119
120
121
122
123 @Override
124 protected void initializePendingTasks(Queue<ViewLifecycleTask<?>> tasks) {
125 if (!(getElement() instanceof Component)) {
126 return;
127 }
128
129 Component component = (Component) getElement();
130 if (!component.isRender() || component.getTemplate() == null) {
131 return;
132 }
133
134 tasks.add(LifecycleTaskFactory.getTask(RenderComponentTask.class, this));
135 }
136
137
138
139
140 @Override
141 protected void initializeSuccessors(Queue<ViewLifecyclePhase> successors) {
142 if (renderParent == null || renderParent.pendingChildren == null) {
143 trace(renderParent == null ? "no-parent" : "no-children");
144 return;
145 }
146
147 synchronized (renderParent) {
148
149
150 if (!renderParent.pendingChildren.remove(getParentPath())) {
151 ViewLifecycle.reportIllegalState("Render phase isn't a pending child\n"
152 + this + "\nRender Parent: " + renderParent);
153 }
154
155 trace("remove-child " + renderParent.getElement().getId() + " " +
156 renderParent.getViewPath() + " " + getParentPath() + " "
157 + renderParent.pendingChildren);
158
159 if (renderParent.pendingChildren.isEmpty()) {
160 successors.add(renderParent);
161 renderParent.trace("pend-rend");
162
163 Set<String> toRecycle = renderParent.pendingChildren;
164 renderParent.pendingChildren = null;
165 RecycleUtils.recycle(toRecycle);
166 }
167 }
168 }
169
170
171
172
173 @Override
174 protected ViewLifecyclePhase initializeSuccessor(LifecycleElement nestedElement, String nestedPath,
175 Component parent) {
176 return null;
177 }
178
179 }