Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UifFormBase |
|
| 1.119047619047619;1.119 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the | |
5 | * "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl1.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
13 | * License for the specific language governing permissions and limitations under | |
14 | * the License. | |
15 | */ | |
16 | package org.kuali.rice.kns.web.spring.form; | |
17 | ||
18 | import java.io.Serializable; | |
19 | import java.util.HashMap; | |
20 | import java.util.Map; | |
21 | import java.util.Properties; | |
22 | import java.util.UUID; | |
23 | ||
24 | import javax.servlet.http.HttpServletRequest; | |
25 | ||
26 | import org.kuali.rice.kns.service.KNSServiceLocatorWeb; | |
27 | import org.kuali.rice.kns.uif.container.View; | |
28 | import org.kuali.rice.kns.uif.service.ViewService; | |
29 | ||
30 | /** | |
31 | * Base form class for views within the KRAD User Interface Framework | |
32 | * <p> | |
33 | * Holds properties necessary to determine the <code>View</code> instance that | |
34 | * will be used to render the UI | |
35 | * </p> | |
36 | * | |
37 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
38 | */ | |
39 | public class UifFormBase implements Serializable { | |
40 | private static final long serialVersionUID = 8432543267099454434L; | |
41 | ||
42 | // current view | |
43 | protected String viewId; | |
44 | protected String viewName; | |
45 | protected String viewTypeName; | |
46 | protected String pageId; | |
47 | protected String methodToCall; | |
48 | protected String formKey; | |
49 | ||
50 | protected String formPostUrl; | |
51 | ||
52 | protected View view; | |
53 | protected View previousView; | |
54 | protected Map<String, String> viewRequestParameters; | |
55 | ||
56 | protected Map<String, Object> newCollectionLines; | |
57 | protected Map<String, String> actionParameters; | |
58 | ||
59 | // navigation | |
60 | protected String returnLocation; | |
61 | protected String returnFormKey; | |
62 | protected String hubLocation; | |
63 | protected String hubFormKey; | |
64 | protected String homeLocation; | |
65 | ||
66 | protected boolean renderFullView; | |
67 | ||
68 | 0 | public UifFormBase() { |
69 | 0 | formKey = generateFormKey(); |
70 | 0 | renderFullView = true; |
71 | ||
72 | 0 | viewRequestParameters = new HashMap<String, String>(); |
73 | 0 | newCollectionLines = new HashMap<String, Object>(); |
74 | 0 | actionParameters = new HashMap<String, String>(); |
75 | 0 | } |
76 | ||
77 | /** | |
78 | * Creates the unique id used to store this "conversation" in the session. | |
79 | * The default method generates a java UUID. | |
80 | * | |
81 | * @return | |
82 | */ | |
83 | protected String generateFormKey() { | |
84 | 0 | return UUID.randomUUID().toString(); |
85 | } | |
86 | ||
87 | /** | |
88 | * Called after Spring binds the request to the form and before the | |
89 | * controller method is invoked. | |
90 | * | |
91 | * @param request | |
92 | * - request object containing the query parameters | |
93 | */ | |
94 | public void postBind(HttpServletRequest request) { | |
95 | // default form post URL to request URL | |
96 | 0 | formPostUrl = request.getRequestURL().toString(); |
97 | 0 | } |
98 | ||
99 | /** | |
100 | * Unique Id for the <code>View</code> instance. This is specified for a | |
101 | * view in its definition by setting the 'id' property. | |
102 | * | |
103 | * @return String view id | |
104 | */ | |
105 | public String getViewId() { | |
106 | 0 | return this.viewId; |
107 | } | |
108 | ||
109 | /** | |
110 | * Setter for the unique view id | |
111 | * | |
112 | * @param viewId | |
113 | */ | |
114 | public void setViewId(String viewId) { | |
115 | 0 | this.viewId = viewId; |
116 | 0 | } |
117 | ||
118 | /** | |
119 | * Name for the <code>View</code> instance. This is specified for a view in | |
120 | * its definition by setting the 'id' property. The name is not necessary | |
121 | * unique and cannot be used by itself to retrieve a view. Typically it is | |
122 | * used with other parameters to identify a view with a certain type (view | |
123 | * type) | |
124 | * | |
125 | * @return String view name | |
126 | */ | |
127 | public String getViewName() { | |
128 | 0 | return this.viewName; |
129 | } | |
130 | ||
131 | /** | |
132 | * Setter for the view name | |
133 | * | |
134 | * @param viewName | |
135 | */ | |
136 | public void setViewName(String viewName) { | |
137 | 0 | this.viewName = viewName; |
138 | 0 | } |
139 | ||
140 | /** | |
141 | * Name for the type of view being requested. This can be used to find | |
142 | * <code>View</code> instances by request parameters (not necessary the | |
143 | * unique id) | |
144 | * | |
145 | * @return String view type name | |
146 | */ | |
147 | public String getViewTypeName() { | |
148 | 0 | return this.viewTypeName; |
149 | } | |
150 | ||
151 | /** | |
152 | * Setter for the view type name | |
153 | * | |
154 | * @param viewTypeName | |
155 | */ | |
156 | public void setViewTypeName(String viewTypeName) { | |
157 | 0 | this.viewTypeName = viewTypeName; |
158 | 0 | } |
159 | ||
160 | /** | |
161 | * Id for the current page being displayed within the view | |
162 | * | |
163 | * @return String page id | |
164 | */ | |
165 | public String getPageId() { | |
166 | 0 | return this.pageId; |
167 | } | |
168 | ||
169 | /** | |
170 | * Setter for the current page id | |
171 | * | |
172 | * @param pageId | |
173 | */ | |
174 | public void setPageId(String pageId) { | |
175 | 0 | this.pageId = pageId; |
176 | 0 | } |
177 | ||
178 | public String getFormPostUrl() { | |
179 | 0 | return this.formPostUrl; |
180 | } | |
181 | ||
182 | public void setFormPostUrl(String formPostUrl) { | |
183 | 0 | this.formPostUrl = formPostUrl; |
184 | 0 | } |
185 | ||
186 | public String getReturnLocation() { | |
187 | 0 | return this.returnLocation; |
188 | } | |
189 | ||
190 | public void setReturnLocation(String returnLocation) { | |
191 | 0 | this.returnLocation = returnLocation; |
192 | 0 | } |
193 | ||
194 | public String getReturnFormKey() { | |
195 | 0 | return this.returnFormKey; |
196 | } | |
197 | ||
198 | public void setReturnFormKey(String returnFormKey) { | |
199 | 0 | this.returnFormKey = returnFormKey; |
200 | 0 | } |
201 | ||
202 | public String getHubLocation() { | |
203 | 0 | return this.hubLocation; |
204 | } | |
205 | ||
206 | public void setHubLocation(String hubLocation) { | |
207 | 0 | this.hubLocation = hubLocation; |
208 | 0 | } |
209 | ||
210 | public String getHubFormKey() { | |
211 | 0 | return this.hubFormKey; |
212 | } | |
213 | ||
214 | public void setHubFormKey(String hubFormKey) { | |
215 | 0 | this.hubFormKey = hubFormKey; |
216 | 0 | } |
217 | ||
218 | public String getHomeLocation() { | |
219 | 0 | return this.homeLocation; |
220 | } | |
221 | ||
222 | public void setHomeLocation(String homeLocation) { | |
223 | 0 | this.homeLocation = homeLocation; |
224 | 0 | } |
225 | ||
226 | /** | |
227 | * Identifies the controller method that should be invoked to fulfill a | |
228 | * request. The value will be matched up against the 'params' setting on the | |
229 | * <code>RequestMapping</code> annotation for the controller method | |
230 | * | |
231 | * @return String method to call | |
232 | */ | |
233 | public String getMethodToCall() { | |
234 | 0 | return this.methodToCall; |
235 | } | |
236 | ||
237 | /** | |
238 | * Setter for the method to call | |
239 | * | |
240 | * @param methodToCall | |
241 | */ | |
242 | public void setMethodToCall(String methodToCall) { | |
243 | 0 | this.methodToCall = methodToCall; |
244 | 0 | } |
245 | ||
246 | /** | |
247 | * Map of parameters that was used to configured the <code>View</code>. | |
248 | * Maintained on the form to rebuild the view on posts and session timeout | |
249 | * | |
250 | * @return Map<String, String> view parameters | |
251 | * @see org.kuali.rice.kns.uif.container.View.getViewRequestParameters() | |
252 | */ | |
253 | public Map<String, String> getViewRequestParameters() { | |
254 | 0 | return this.viewRequestParameters; |
255 | } | |
256 | ||
257 | /** | |
258 | * Setter for the view's request parameter map | |
259 | * | |
260 | * @param viewRequestParameters | |
261 | */ | |
262 | public void setViewRequestParameters(Map<String, String> viewRequestParameters) { | |
263 | 0 | this.viewRequestParameters = viewRequestParameters; |
264 | 0 | } |
265 | ||
266 | /** | |
267 | * Holds instances for collection add lines. The key of the Map gives the | |
268 | * collection name the line instance applies to, the Map value is an | |
269 | * instance of the collection object class that holds the new line data | |
270 | * | |
271 | * @return Map<String, Object> new collection lines | |
272 | */ | |
273 | public Map<String, Object> getNewCollectionLines() { | |
274 | 0 | return this.newCollectionLines; |
275 | } | |
276 | ||
277 | /** | |
278 | * Setter for the new collection lines Map | |
279 | * | |
280 | * @param newCollectionLines | |
281 | */ | |
282 | public void setNewCollectionLines(Map<String, Object> newCollectionLines) { | |
283 | 0 | this.newCollectionLines = newCollectionLines; |
284 | 0 | } |
285 | ||
286 | /** | |
287 | * Map of parameters sent for the invoked action | |
288 | * <p> | |
289 | * Many times besides just setting the method to call actions need to send | |
290 | * additional parameters. For instance the method being called might do a | |
291 | * redirect, in which case the action needs to send parameters for the | |
292 | * redirect URL. An example of this is redirecting to a <code>Lookup</code> | |
293 | * view. In some cases the parameters that need to be sent conflict with | |
294 | * properties already on the form, and putting all the action parameters as | |
295 | * form properties would grow massive (in addition to adds an additional | |
296 | * step from the XML config). So this general map solves those issues. | |
297 | * </p> | |
298 | * | |
299 | * @return Map<String, String> action parameters | |
300 | */ | |
301 | public Map<String, String> getActionParameters() { | |
302 | 0 | return this.actionParameters; |
303 | } | |
304 | ||
305 | /** | |
306 | * Returns the action parameters map as a <code>Properties</code> instance | |
307 | * | |
308 | * @return Properties action parameters | |
309 | */ | |
310 | public Properties getActionParametersAsProperties() { | |
311 | 0 | Properties actionProperties = new Properties(); |
312 | ||
313 | 0 | if (actionParameters != null) { |
314 | 0 | for (Map.Entry<String, String> actionParameter : actionParameters.entrySet()) { |
315 | 0 | actionProperties.put(actionParameter.getKey(), actionParameter.getValue()); |
316 | } | |
317 | } | |
318 | ||
319 | 0 | return actionProperties; |
320 | } | |
321 | ||
322 | /** | |
323 | * Setter for the action parameters map | |
324 | * | |
325 | * @param actionParameters | |
326 | */ | |
327 | public void setActionParameters(Map<String, String> actionParameters) { | |
328 | 0 | this.actionParameters = actionParameters; |
329 | 0 | } |
330 | ||
331 | /** | |
332 | * Retrieves the value for the given action parameter, or empty string if | |
333 | * not found | |
334 | * | |
335 | * @param actionParameterName | |
336 | * - name of the action parameter to retrieve value for | |
337 | * @return String parameter value or empty string | |
338 | */ | |
339 | public String getActionParamaterValue(String actionParameterName) { | |
340 | 0 | if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) { |
341 | 0 | return actionParameters.get(actionParameterName); |
342 | } | |
343 | ||
344 | 0 | return ""; |
345 | } | |
346 | ||
347 | /** | |
348 | * Key string that identifies the form instance in session storage | |
349 | * <p> | |
350 | * When the view is posted, the previous form instance is retrieved and then | |
351 | * populated from the request parameters. This key string is retrieve the | |
352 | * session form from the session service | |
353 | * </p> | |
354 | * | |
355 | * @return String form session key | |
356 | */ | |
357 | public String getFormKey() { | |
358 | 0 | return this.formKey; |
359 | } | |
360 | ||
361 | /** | |
362 | * Setter for the form's session key | |
363 | * | |
364 | * @param formKey | |
365 | */ | |
366 | public void setFormKey(String formKey) { | |
367 | 0 | this.formKey = formKey; |
368 | 0 | } |
369 | ||
370 | /** | |
371 | * @return the renderFullView | |
372 | */ | |
373 | public boolean isRenderFullView() { | |
374 | 0 | return this.renderFullView; |
375 | } | |
376 | ||
377 | /** | |
378 | * @param renderFullView | |
379 | */ | |
380 | public void setRenderFullView(boolean renderFullView) { | |
381 | 0 | this.renderFullView = renderFullView; |
382 | 0 | } |
383 | ||
384 | /** | |
385 | * View instance associated with the form. Used to render the user interface | |
386 | * | |
387 | * @return View | |
388 | */ | |
389 | public View getView() { | |
390 | 0 | return this.view; |
391 | } | |
392 | ||
393 | /** | |
394 | * Setter for the view instance | |
395 | * | |
396 | * @param view | |
397 | */ | |
398 | public void setView(View view) { | |
399 | 0 | this.view = view; |
400 | 0 | } |
401 | ||
402 | /** | |
403 | * View instance for the page that made a request. Since a new view instance | |
404 | * gets initialized for each request before the controller logic is invoked, | |
405 | * any state about the previous view is lost. This could be needed to read | |
406 | * metadata from the view for such things as collection processing. When | |
407 | * this is necessary the previous view instance can be retrieved | |
408 | * | |
409 | * @return View instance | |
410 | */ | |
411 | public View getPreviousView() { | |
412 | 0 | return this.previousView; |
413 | } | |
414 | ||
415 | /** | |
416 | * Setter for the previous view instance | |
417 | * | |
418 | * @param previousView | |
419 | */ | |
420 | public void setPreviousView(View previousView) { | |
421 | 0 | this.previousView = previousView; |
422 | 0 | } |
423 | ||
424 | /** | |
425 | * Instance of the <code>ViewService</code> that can be used to retrieve | |
426 | * <code>View</code> instances | |
427 | * | |
428 | * @return ViewService implementation | |
429 | */ | |
430 | protected ViewService getViewService() { | |
431 | 0 | return KNSServiceLocatorWeb.getViewService(); |
432 | } | |
433 | ||
434 | } |