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
33 public class RunComponentModifiersTask extends ViewLifecycleTaskBase<Component> {
34
35
36
37
38 public RunComponentModifiersTask() {
39 super(Component.class);
40 }
41
42
43
44
45
46
47
48 @Override
49 protected void performLifecycleTask() {
50 Component component = (Component) getElementState().getElement();
51
52 List<ComponentModifier> componentModifiers = component.getComponentModifiers();
53 if (componentModifiers == null) {
54 return;
55 }
56
57 Object model = ViewLifecycle.getModel();
58 String runPhase = getElementState().getViewPhase();
59 for (ComponentModifier modifier : component.getComponentModifiers()) {
60 if (!StringUtils.equals(modifier.getRunPhase(), runPhase)) {
61 continue;
62 }
63
64 boolean runCondition = true;
65 if (StringUtils.isNotBlank(modifier.getRunCondition())) {
66 Map<String, Object> context = new HashMap<String, Object>();
67 context.putAll(component.getContext());
68
69 if (context.isEmpty()) {
70 context.putAll(ViewLifecycle.getView().getContext());
71 context.put(UifConstants.ContextVariableNames.COMPONENT, component);
72 }
73
74 String conditionEvaluation = ViewLifecycle.getExpressionEvaluator().evaluateExpressionTemplate(context,
75 modifier.getRunCondition());
76 runCondition = Boolean.parseBoolean(conditionEvaluation);
77 }
78
79 if (runCondition) {
80 modifier.performModification(model, component);
81 }
82 }
83 }
84 }