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.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.modifier.ComponentModifier;
26
27
28
29
30
31
32 public class RunComponentModifiersTask extends AbstractViewLifecycleTask {
33
34
35
36
37
38
39 public RunComponentModifiersTask(ViewLifecyclePhase phase) {
40 super(phase);
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54 @Override
55 protected void performLifecycleTask() {
56 Component component = getPhase().getComponent();
57
58 List<ComponentModifier> componentModifiers = component.getComponentModifiers();
59 if (componentModifiers == null) {
60 return;
61 }
62
63 Object model = getPhase().getModel();
64 String runPhase = getPhase().getViewPhase();
65 for (ComponentModifier modifier : component.getComponentModifiers()) {
66
67 if (StringUtils.equals(runPhase, UifConstants.ViewPhases.INITIALIZE)) {
68 modifier.performInitialization(model, component);
69 }
70
71
72 if (StringUtils.equals(modifier.getRunPhase(), runPhase)) {
73
74 boolean runModifier = true;
75 if (StringUtils.isNotBlank(modifier.getRunCondition())) {
76 Map<String, Object> context = new HashMap<String, Object>();
77 context.put(UifConstants.ContextVariableNames.COMPONENT, component);
78 context.put(UifConstants.ContextVariableNames.VIEW, ViewLifecycle.getView());
79
80 String conditionEvaluation = ViewLifecycle.getHelper().getExpressionEvaluator()
81 .evaluateExpressionTemplate(context, modifier.getRunCondition());
82 runModifier = Boolean.parseBoolean(conditionEvaluation);
83 }
84
85 if (runModifier) {
86 modifier.performModification(model, component);
87 }
88 }
89 }
90 }
91
92 }