1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.bind;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20 import org.kuali.rice.krad.uif.UifParameters;
21 import org.kuali.rice.krad.uif.view.View;
22 import org.kuali.rice.krad.uif.UifConstants.ViewType;
23 import org.kuali.rice.krad.uif.service.ViewService;
24 import org.kuali.rice.krad.util.KRADUtils;
25 import org.kuali.rice.krad.web.form.UifFormBase;
26 import org.springframework.core.convert.ConversionService;
27 import org.springframework.util.Assert;
28 import org.springframework.validation.AbstractPropertyBindingResult;
29 import org.springframework.web.bind.ServletRequestDataBinder;
30
31 import javax.servlet.ServletRequest;
32 import javax.servlet.http.HttpServletRequest;
33 import java.util.Map;
34
35
36
37
38
39
40
41 public class UifServletRequestDataBinder extends ServletRequestDataBinder {
42 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
43 UifServletRequestDataBinder.class);
44
45 private UifBeanPropertyBindingResult bindingResult;
46 private ConversionService conversionService;
47
48 public UifServletRequestDataBinder(Object target) {
49 super(target);
50 setBindingErrorProcessor(new UifBindingErrorProcessor());
51 }
52
53 public UifServletRequestDataBinder(Object target, String name) {
54 super(target, name);
55 setBindingErrorProcessor(new UifBindingErrorProcessor());
56 }
57
58
59
60
61
62
63 @Override
64 public void initBeanPropertyAccess() {
65 Assert.state(this.bindingResult == null,
66 "DataBinder is already initialized - call initBeanPropertyAccess before other configuration methods");
67 this.bindingResult = new UifBeanPropertyBindingResult(getTarget(), getObjectName(), isAutoGrowNestedPaths(),
68 getAutoGrowCollectionLimit());
69 if (this.conversionService != null) {
70 this.bindingResult.initConversion(this.conversionService);
71 }
72 }
73
74
75
76
77
78
79 @Override
80 protected AbstractPropertyBindingResult getInternalBindingResult() {
81 if (this.bindingResult == null) {
82 initBeanPropertyAccess();
83 }
84 return this.bindingResult;
85 }
86
87
88
89
90
91
92 @Override
93 public void initDirectFieldAccess() {
94 LOG.error("Direct Field access is not allowed in UifServletRequestDataBinder.");
95 throw new RuntimeException("Direct Field access is not allowed in Kuali");
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 @Override
118 public void bind(ServletRequest request) {
119 super.bind(request);
120
121 UifFormBase form = (UifFormBase) this.getTarget();
122
123
124 if (!form.isUpdateComponentRequest() && !form.isUpdateNoneRequest() && !form.isUpdateDialogRequest()) {
125 View view = null;
126
127
128 String viewId = request.getParameter(UifParameters.VIEW_ID);
129 if (viewId != null) {
130 view = getViewService().getViewById(viewId);
131 } else {
132
133 String viewTypeName = request.getParameter(UifParameters.VIEW_TYPE_NAME);
134 ViewType viewType = StringUtils.isBlank(viewTypeName) ? form.getViewTypeName() : ViewType.valueOf(
135 viewTypeName);
136
137 if (viewType != null) {
138 Map<String, String> parameterMap = KRADUtils.translateRequestParameterMap(
139 request.getParameterMap());
140 view = getViewService().getViewByType(viewType, parameterMap);
141 }
142
143
144 if (view == null) {
145 view = getViewFromPreviousModel(form);
146
147 if (view != null) {
148 LOG.warn("Obtained viewId from cached form, this may not be safe!");
149 }
150 }
151 }
152
153 if (view != null) {
154 form.setViewId(view.getId());
155 form.setView(view);
156 } else {
157 form.setViewId(null);
158 form.setView(null);
159 }
160 }
161
162 form.postBind((HttpServletRequest) request);
163 }
164
165 protected View getViewFromPreviousModel(UifFormBase form) {
166
167 if (form.getViewId() != null) {
168 return getViewService().getViewById(form.getViewId());
169 }
170
171 return null;
172 }
173
174 public ViewService getViewService() {
175 return KRADServiceLocatorWeb.getViewService();
176 }
177
178 }
179
180