1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle.finalize;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.uif.UifConstants;
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.lifecycle.LifecycleElementState;
22 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
23 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleTaskBase;
24 import org.kuali.rice.krad.web.form.UifFormBase;
25
26
27
28
29
30
31 public class AddFocusAndJumpDataAttributesTask extends ViewLifecycleTaskBase<Component> {
32
33
34
35
36
37
38 public AddFocusAndJumpDataAttributesTask() {
39 super(Component.class);
40 }
41
42
43
44
45 @Override
46 protected void performLifecycleTask() {
47 LifecycleElementState elementState = getElementState();
48 String phase = elementState.getViewPhase();
49 String viewPath = elementState.getViewPath();
50 if (!ViewLifecycle.isRefreshComponent(phase, viewPath)) {
51 return;
52 }
53
54 Component component = (Component) getElementState().getElement();
55 Object model = ViewLifecycle.getModel();
56
57 UifFormBase formBase = (UifFormBase) model;
58
59
60 if (((UifFormBase) model).getView().getCurrentPage().isAutoFocus() && StringUtils.isNotBlank(formBase.getFocusId())) {
61 component.addDataAttribute(UifConstants.ActionDataAttributes.FOCUS_ID, formBase.getFocusId());
62 } else if (((UifFormBase) model).getView().getCurrentPage().isAutoFocus()) {
63 component.addDataAttribute(UifConstants.ActionDataAttributes.FOCUS_ID, UifConstants.Order.FIRST.name());
64 }
65
66
67 if (StringUtils.isNotBlank(formBase.getJumpToId())) {
68 component.addDataAttribute(UifConstants.ActionDataAttributes.JUMP_TO_ID, formBase.getJumpToId());
69 }
70
71
72 if (StringUtils.isNotBlank(formBase.getJumpToName())) {
73 component.addDataAttribute(UifConstants.ActionDataAttributes.JUMP_TO_NAME, formBase.getJumpToName());
74 }
75 }
76
77 }