1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.controller;
17
18 import java.util.Enumeration;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Map.Entry;
22 import java.util.Properties;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.rice.core.api.config.property.ConfigContext;
29 import org.kuali.rice.core.api.exception.RiceRuntimeException;
30 import org.kuali.rice.kim.api.identity.Person;
31 import org.kuali.rice.krad.exception.AuthorizationException;
32 import org.kuali.rice.krad.lookup.LookupUtils;
33 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
34 import org.kuali.rice.krad.service.ModuleService;
35 import org.kuali.rice.krad.uif.UifConstants;
36 import org.kuali.rice.krad.uif.UifParameters;
37 import org.kuali.rice.krad.uif.UifPropertyPaths;
38 import org.kuali.rice.krad.uif.field.AttributeQueryResult;
39 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
40 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRefreshBuild;
41 import org.kuali.rice.krad.uif.service.ViewService;
42 import org.kuali.rice.krad.uif.view.DialogManager;
43 import org.kuali.rice.krad.uif.view.MessageView;
44 import org.kuali.rice.krad.uif.view.View;
45 import org.kuali.rice.krad.util.GlobalVariables;
46 import org.kuali.rice.krad.util.KRADConstants;
47 import org.kuali.rice.krad.util.KRADUtils;
48 import org.kuali.rice.krad.util.UrlFactory;
49 import org.kuali.rice.krad.web.form.HistoryFlow;
50 import org.kuali.rice.krad.web.form.HistoryManager;
51 import org.kuali.rice.krad.web.form.UifFormBase;
52 import org.kuali.rice.krad.web.form.UifFormManager;
53 import org.springframework.util.Assert;
54 import org.springframework.validation.BindingResult;
55 import org.springframework.web.bind.annotation.ModelAttribute;
56 import org.springframework.web.bind.annotation.RequestMapping;
57 import org.springframework.web.bind.annotation.RequestMethod;
58 import org.springframework.web.bind.annotation.ResponseBody;
59 import org.springframework.web.servlet.ModelAndView;
60 import org.springframework.web.servlet.view.UrlBasedViewResolver;
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public abstract class UifControllerBase {
81 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifControllerBase.class);
82
83 private UrlBasedViewResolver viewResolver;
84
85
86
87
88
89
90
91
92
93 @ModelAttribute(value = "KualiForm")
94 public UifFormBase initForm(HttpServletRequest request, HttpServletResponse response) {
95
96 UifFormManager uifFormManager = (UifFormManager) request.getSession().getAttribute(UifParameters.FORM_MANAGER);
97 if (uifFormManager == null) {
98 uifFormManager = new UifFormManager();
99 request.getSession().setAttribute(UifParameters.FORM_MANAGER, uifFormManager);
100 }
101
102
103 GlobalVariables.setUifFormManager(uifFormManager);
104
105
106 UifFormBase requestForm = createInitialForm(request);
107
108 String formKeyParam = request.getParameter(UifParameters.FORM_KEY);
109 if (StringUtils.isNotBlank(formKeyParam)) {
110
111 uifFormManager.updateFormWithSession(requestForm, formKeyParam);
112 }
113
114
115 String requestedFormKey = request.getParameter(UifParameters.REQUESTED_FORM_KEY);
116 if (StringUtils.isNotBlank(requestedFormKey)) {
117 requestForm.setRequestedFormKey(requestedFormKey);
118 } else {
119 requestForm.setRequestedFormKey(formKeyParam);
120 }
121
122
123 String referer = request.getHeader(UifConstants.REFERER);
124
125
126 if (StringUtils.isBlank(referer) && StringUtils.isBlank(requestForm.getReturnLocation())) {
127 requestForm.setReturnLocation(UifConstants.NO_RETURN);
128 } else if (StringUtils.isBlank(requestForm.getReturnLocation())) {
129 requestForm.setReturnLocation(referer);
130 }
131
132
133 if (requestForm.getInitialRequestParameters() == null) {
134 Map<String, String[]> requestParams = new HashMap<String, String[]>();
135 Enumeration<String> names = request.getParameterNames();
136
137 while (names != null && names.hasMoreElements()) {
138 String name = KRADUtils.stripXSSPatterns(names.nextElement());
139 String[] values = KRADUtils.stripXSSPatterns(request.getParameterValues(name));
140
141 requestParams.put(name, values);
142 }
143
144 requestParams.remove(UifConstants.UrlParams.LOGIN_USER);
145 requestForm.setInitialRequestParameters(requestParams);
146 }
147
148
149 String requestUrl = KRADUtils.stripXSSPatterns(KRADUtils.getFullURL(request));
150 requestForm.setRequestUrl(requestUrl);
151
152 Object historyManager = request.getSession().getAttribute(UifConstants.HistoryFlow.HISTORY_MANAGER);
153 String flowKey = request.getParameter(UifConstants.HistoryFlow.FLOW);
154
155
156 if (historyManager != null && historyManager instanceof HistoryManager) {
157 requestForm.setHistoryManager((HistoryManager) historyManager);
158 requestForm.setFlowKey(flowKey);
159 }
160
161
162 request.setAttribute(UifConstants.REQUEST_FORM, requestForm);
163
164 return requestForm;
165 }
166
167
168
169
170
171
172
173
174 protected abstract UifFormBase createInitialForm(HttpServletRequest request);
175
176
177
178
179 @MethodAccessible
180 @RequestMapping()
181 public ModelAndView defaultMapping(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
182 HttpServletRequest request, HttpServletResponse response) {
183 return start(form, request, response);
184 }
185
186
187
188
189
190 @MethodAccessible
191 @RequestMapping(params = "methodToCall=start")
192 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, HttpServletRequest request,
193 HttpServletResponse response) {
194
195
196
197 if (form.getView() != null) {
198
199
200 form.addViewThatNeedsDefaultValuesApplied(form.getViewId());
201
202 String methodToCall = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
203 checkViewAuthorization(form, methodToCall);
204 }
205
206 return getUIFModelAndView(form);
207 }
208
209
210
211
212
213
214
215
216
217
218
219
220
221 public void checkViewAuthorization(UifFormBase form, String methodToCall) throws AuthorizationException {
222
223 if (GlobalVariables.getUserSession() == null) {
224 return;
225 }
226
227 Person user = GlobalVariables.getUserSession().getPerson();
228
229 boolean canOpenView = form.getView().getAuthorizer().canOpenView(form.getView(), form, user);
230 if (!canOpenView) {
231 throw new AuthorizationException(user.getPrincipalName(), "open", form.getView().getId(),
232 "User '" + user.getPrincipalName() + "' is not authorized to open view ID: " +
233 form.getView().getId(), null);
234 }
235 }
236
237
238
239
240 @MethodAccessible
241 @RequestMapping(params = "methodToCall=sessionTimeout")
242 public ModelAndView sessionTimeout(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
243 HttpServletRequest request, HttpServletResponse response) {
244 return getUIFModelAndView(form);
245 }
246
247
248
249
250
251
252
253 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
254 public ModelAndView addLine(@ModelAttribute("KualiForm") final UifFormBase uifForm, BindingResult result,
255 HttpServletRequest request, HttpServletResponse response) {
256 final String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
257 final String selectedCollectionId = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID);
258
259 if (StringUtils.isBlank(selectedCollectionPath)) {
260 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
261 }
262
263 ViewLifecycle.encapsulateLifecycle(uifForm.getView(), uifForm, uifForm.getViewPostMetadata(), null, request,
264 response, new Runnable() {
265 @Override
266 public void run() {
267 ViewLifecycle.getHelper().processCollectionAddLine(uifForm, selectedCollectionId,
268 selectedCollectionPath);
269 }
270 });
271
272 return getUIFModelAndView(uifForm);
273 }
274
275
276
277
278
279
280
281
282
283
284
285
286 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addBlankLine")
287 public ModelAndView addBlankLine(@ModelAttribute("KualiForm") final UifFormBase uifForm, HttpServletRequest request,
288 HttpServletResponse response) {
289
290 final String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
291 final String selectedCollectionId = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID);
292
293 if (StringUtils.isBlank(selectedCollectionPath)) {
294 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
295 }
296
297 ViewLifecycle.encapsulateLifecycle(uifForm.getView(), uifForm, uifForm.getViewPostMetadata(), null, request,
298 response, new Runnable() {
299 @Override
300 public void run() {
301 ViewLifecycle.getHelper().processCollectionAddBlankLine(uifForm, selectedCollectionId,
302 selectedCollectionPath);
303 }
304 });
305
306 return getUIFModelAndView(uifForm);
307 }
308
309
310
311
312
313 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveLine")
314 public ModelAndView saveLine(@ModelAttribute("KualiForm") final UifFormBase uifForm, BindingResult result,
315 HttpServletRequest request, HttpServletResponse response) {
316
317 final String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
318 final String selectedCollectionId = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID);
319
320 if (StringUtils.isBlank(selectedCollectionPath)) {
321 throw new RuntimeException("Selected collection was not set for add line action, cannot add new line");
322 }
323
324 String selectedLine = uifForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
325 final int selectedLineIndex;
326 if (StringUtils.isNotBlank(selectedLine)) {
327 selectedLineIndex = Integer.parseInt(selectedLine);
328 } else {
329 selectedLineIndex = -1;
330 }
331
332 if (selectedLineIndex == -1) {
333 throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line");
334 }
335
336 ViewLifecycle.encapsulateLifecycle(uifForm.getView(), uifForm, uifForm.getViewPostMetadata(), null, request,
337 response, new Runnable() {
338 @Override
339 public void run() {
340 ViewLifecycle.getHelper().processCollectionSaveLine(uifForm, selectedCollectionId,
341 selectedCollectionPath, selectedLineIndex);
342 }
343 });
344
345 return getUIFModelAndView(uifForm);
346 }
347
348
349
350
351
352
353
354 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine")
355 public ModelAndView deleteLine(@ModelAttribute("KualiForm") final UifFormBase uifForm, BindingResult result,
356 HttpServletRequest request, HttpServletResponse response) {
357
358 final String selectedCollectionPath = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
359 final String selectedCollectionId = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID);
360
361 if (StringUtils.isBlank(selectedCollectionPath)) {
362 throw new RuntimeException("Selected collection was not set for delete line action, cannot delete line");
363 }
364
365 String selectedLine = uifForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
366 final int selectedLineIndex;
367 if (StringUtils.isNotBlank(selectedLine)) {
368 selectedLineIndex = Integer.parseInt(selectedLine);
369 } else {
370 selectedLineIndex = -1;
371 }
372
373 if (selectedLineIndex == -1) {
374 throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line");
375 }
376
377 ViewLifecycle.encapsulateLifecycle(uifForm.getView(), uifForm, uifForm.getViewPostMetadata(), null, request,
378 response, new Runnable() {
379 @Override
380 public void run() {
381 ViewLifecycle.getHelper().processCollectionDeleteLine(uifForm, selectedCollectionId,
382 selectedCollectionPath, selectedLineIndex);
383 }
384 });
385
386 return getUIFModelAndView(uifForm);
387 }
388
389
390
391
392 @RequestMapping(params = "methodToCall=cancel")
393 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
394 HttpServletRequest request, HttpServletResponse response) {
395 return back(form, result, request, response);
396 }
397
398
399
400
401
402 @RequestMapping(params = "methodToCall=back")
403 public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
404 HttpServletRequest request, HttpServletResponse response) {
405 Properties props = new Properties();
406 props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
407
408 if (StringUtils.isNotBlank(form.getReturnFormKey())) {
409 props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
410 }
411
412 HistoryFlow historyFlow = form.getHistoryManager().getMostRecentFlowByFormKey(form.getFlowKey(),
413 form.getRequestedFormKey());
414
415 String returnUrl = form.getReturnLocation();
416
417
418 if (historyFlow != null) {
419 returnUrl = historyFlow.getFlowReturnPoint();
420 }
421
422
423 String returnToStart = form.getActionParamaterValue(UifConstants.HistoryFlow.RETURN_TO_START);
424 if (StringUtils.isBlank(returnToStart)) {
425 returnToStart = request.getParameter(UifConstants.HistoryFlow.RETURN_TO_START);
426 }
427
428 if (StringUtils.isNotBlank(returnToStart) && Boolean.parseBoolean(returnToStart) && historyFlow != null &&
429 StringUtils.isNotBlank(historyFlow.getFlowStartPoint())) {
430 returnUrl = historyFlow.getFlowStartPoint();
431 }
432
433
434 if (StringUtils.isBlank(returnUrl) || returnUrl.equals(UifConstants.NO_RETURN)) {
435 returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY);
436 }
437
438
439 GlobalVariables.getUifFormManager().removeSessionForm(form);
440
441 return performRedirect(form, returnUrl, props);
442 }
443
444
445
446
447
448
449 @RequestMapping(params = "methodToCall=returnToPrevious")
450 public ModelAndView returnToPrevious(@ModelAttribute("KualiForm") UifFormBase form) {
451
452 return returnToHistory(form, false);
453 }
454
455
456
457
458
459
460 @RequestMapping(params = "methodToCall=returnToHub")
461 public ModelAndView returnToHub(@ModelAttribute("KualiForm") UifFormBase form) {
462
463 return returnToHistory(form, true);
464 }
465
466
467
468
469
470
471
472
473
474 public ModelAndView returnToHistory(UifFormBase form, boolean homeFlag) {
475 String returnUrl = form.getReturnLocation();
476
477 if (StringUtils.isBlank(returnUrl) || homeFlag) {
478 returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY);
479 }
480
481
482 Properties props = new Properties();
483 props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
484
485
486 GlobalVariables.getUifFormManager().removeSessionForm(form);
487
488 return performRedirect(form, returnUrl, props);
489 }
490
491
492
493
494 @MethodAccessible
495 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
496 public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
497 HttpServletRequest request, HttpServletResponse response) {
498 String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
499
500
501 form.setDirtyForm(false);
502
503 return getUIFModelAndView(form, pageId);
504 }
505
506
507
508
509 @MethodAccessible
510 @RequestMapping(params = "methodToCall=refresh")
511 public ModelAndView refresh(@ModelAttribute("KualiForm") final UifFormBase form, BindingResult result,
512 final HttpServletRequest request, HttpServletResponse response) throws Exception {
513
514 ViewLifecycle.encapsulateLifecycle(form.getView(), form, form.getViewPostMetadata(), null, request, response,
515 new ViewLifecycleRefreshBuild());
516
517 return getUIFModelAndView(form);
518 }
519
520
521
522
523
524 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=performLookup")
525 public ModelAndView performLookup(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
526 HttpServletRequest request, HttpServletResponse response) {
527 Properties lookupParameters = form.getActionParametersAsProperties();
528
529 String lookupObjectClassName = (String) lookupParameters.get(UifParameters.DATA_OBJECT_CLASS_NAME);
530 Class<?> lookupObjectClass = null;
531 try {
532 lookupObjectClass = Class.forName(lookupObjectClassName);
533 } catch (ClassNotFoundException e) {
534 LOG.error("Unable to get class for name: " + lookupObjectClassName);
535 throw new RuntimeException("Unable to get class for name: " + lookupObjectClassName, e);
536 }
537
538
539 String lookupParameterString = (String) lookupParameters.get(UifParameters.LOOKUP_PARAMETERS);
540 if (lookupParameterString != null) {
541 Map<String, String> lookupParameterFields = KRADUtils.getMapFromParameterString(lookupParameterString);
542 for (Entry<String, String> lookupParameter : lookupParameterFields.entrySet()) {
543 String lookupParameterValue = LookupUtils.retrieveLookupParameterValue(form, request, lookupObjectClass,
544 lookupParameter.getValue(), lookupParameter.getKey());
545
546 if (StringUtils.isNotBlank(lookupParameterValue)) {
547 lookupParameters.put(UifPropertyPaths.LOOKUP_CRITERIA + "['" + lookupParameter.getValue() + "']",
548 lookupParameterValue);
549 }
550 }
551
552 lookupParameters.remove(UifParameters.LOOKUP_PARAMETERS);
553 }
554
555 String baseLookupUrl = (String) lookupParameters.get(UifParameters.BASE_LOOKUP_URL);
556 lookupParameters.remove(UifParameters.BASE_LOOKUP_URL);
557
558
559 lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START);
560 String autoSearchString = (String) lookupParameters.get(UifParameters.AUTO_SEARCH);
561 if (Boolean.parseBoolean(autoSearchString)) {
562 lookupParameters.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.SEARCH);
563 }
564
565 lookupParameters.put(UifParameters.RETURN_LOCATION, form.getFormPostUrl());
566 lookupParameters.put(UifParameters.RETURN_FORM_KEY, form.getFormKey());
567
568
569 if (lookupObjectClass != null) {
570 ModuleService responsibleModuleService =
571 KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(lookupObjectClass);
572 if (responsibleModuleService != null && responsibleModuleService.isExternalizable(lookupObjectClass)) {
573 String lookupUrl = responsibleModuleService.getExternalizableDataObjectLookupUrl(lookupObjectClass,
574 lookupParameters);
575
576 return performRedirect(form, lookupUrl, new Properties());
577 }
578 }
579
580 return performRedirect(form, baseLookupUrl, lookupParameters);
581 }
582
583
584
585
586
587 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=checkForm")
588 public ModelAndView checkForm(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
589 HttpServletRequest request, HttpServletResponse response) {
590 KRADServiceLocatorWeb.getViewValidationService().validateViewSimulation(form);
591
592 return getUIFModelAndView(form);
593 }
594
595
596
597
598
599
600
601 @MethodAccessible
602 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest")
603 public
604 @ResponseBody
605 AttributeQueryResult performFieldSuggest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
606 HttpServletRequest request, HttpServletResponse response) {
607
608
609 Map<String, String> queryParameters = new HashMap<String, String>();
610 for (Object parameterName : request.getParameterMap().keySet()) {
611 if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) {
612 String fieldName = StringUtils.substringAfter(parameterName.toString(),
613 UifParameters.QUERY_PARAMETER + ".");
614 String fieldValue = request.getParameter(parameterName.toString());
615 queryParameters.put(fieldName, fieldValue);
616 }
617 }
618
619
620 String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID);
621 if (StringUtils.isBlank(queryFieldId)) {
622 throw new RuntimeException(
623 "Unable to find id for field to perform query on under request parameter name: " +
624 UifParameters.QUERY_FIELD_ID);
625 }
626
627
628 String queryTerm = request.getParameter(UifParameters.QUERY_TERM);
629 if (StringUtils.isBlank(queryTerm)) {
630 throw new RuntimeException(
631 "Unable to find id for query term value for attribute query on under request parameter name: " +
632 UifParameters.QUERY_TERM);
633 }
634
635
636 AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService().performFieldSuggestQuery(
637 form.getViewPostMetadata(), queryFieldId, queryTerm, queryParameters);
638
639 return queryResult;
640 }
641
642
643
644
645
646
647
648
649 @MethodAccessible
650 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldQuery")
651 public
652 @ResponseBody
653 AttributeQueryResult performFieldQuery(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
654 HttpServletRequest request, HttpServletResponse response) {
655
656
657 Map<String, String> queryParameters = new HashMap<String, String>();
658 for (Object parameterName : request.getParameterMap().keySet()) {
659 if (parameterName.toString().startsWith(UifParameters.QUERY_PARAMETER + ".")) {
660 String fieldName = StringUtils.substringAfter(parameterName.toString(),
661 UifParameters.QUERY_PARAMETER + ".");
662 String fieldValue = request.getParameter(parameterName.toString());
663 queryParameters.put(fieldName, fieldValue);
664 }
665 }
666
667
668 String queryFieldId = request.getParameter(UifParameters.QUERY_FIELD_ID);
669 if (StringUtils.isBlank(queryFieldId)) {
670 throw new RuntimeException(
671 "Unable to find id for field to perform query on under request parameter name: " +
672 UifParameters.QUERY_FIELD_ID);
673 }
674
675
676 AttributeQueryResult queryResult = KRADServiceLocatorWeb.getAttributeQueryService().performFieldQuery(
677 form.getViewPostMetadata(), queryFieldId, queryParameters);
678
679 return queryResult;
680 }
681
682
683
684
685
686
687
688
689 protected boolean hasDialogBeenDisplayed(String dialogId, UifFormBase form) {
690 return (form.getDialogManager().hasDialogBeenDisplayed(dialogId));
691 }
692
693
694
695
696
697
698
699
700 protected boolean hasDialogBeenAnswered(String dialogId, UifFormBase form) {
701 return (form.getDialogManager().hasDialogBeenAnswered(dialogId));
702 }
703
704
705
706
707
708
709
710
711 protected void resetDialogStatus(String dialogId, UifFormBase form) {
712 form.getDialogManager().resetDialogStatus(dialogId);
713 }
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742 protected boolean getBooleanDialogResponse(String dialogId, UifFormBase form, HttpServletRequest request,
743 HttpServletResponse response) {
744 DialogManager dm = form.getDialogManager();
745 if (!dm.hasDialogBeenAnswered(dialogId)) {
746
747
748
749
750 throw new RiceRuntimeException("Dialog has not yet been answered by client. " +
751 "Check that hasDialogBeenAnswered(id) returns true.");
752 }
753
754 return dm.wasDialogAnswerAffirmative(dialogId);
755 }
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785 protected String getStringDialogResponse(String dialogId, UifFormBase form, HttpServletRequest request,
786 HttpServletResponse response) {
787 DialogManager dm = form.getDialogManager();
788 if (!dm.hasDialogBeenAnswered(dialogId)) {
789
790
791
792 throw new RiceRuntimeException("Dialog has not yet been answered by client. " +
793 "Check that hasDialogBeenAnswered(id) returns true.");
794 }
795
796 return dm.getDialogAnswer(dialogId);
797 }
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815 protected ModelAndView showDialog(String dialogId, UifFormBase form, HttpServletRequest request,
816 HttpServletResponse response) {
817
818 form.setLightboxScript("openLightboxOnLoad('" + dialogId + "');");
819 form.getDialogManager().addDialog(dialogId, form.getMethodToCall());
820
821
822
823 if (form.isAjaxRequest()) {
824 form.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATEDIALOG.getKey());
825 form.setUpdateComponentId(dialogId);
826 }
827
828 return getUIFModelAndView(form);
829 }
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846 @MethodAccessible
847 @RequestMapping(params = "methodToCall=returnFromLightbox")
848 public ModelAndView returnFromLightbox(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
849 HttpServletRequest request, HttpServletResponse response) {
850 String newMethodToCall = "";
851
852
853 DialogManager dm = form.getDialogManager();
854 String dialogId = dm.getCurrentDialogId();
855 if (dialogId == null) {
856
857
858
859 newMethodToCall = "start";
860 } else {
861 dm.setDialogAnswer(dialogId, form.getDialogResponse());
862 dm.setDialogExplanation(dialogId, form.getDialogExplanation());
863 newMethodToCall = dm.getDialogReturnMethod(dialogId);
864 dm.setCurrentDialogId(null);
865 }
866
867
868 Properties props = new Properties();
869 props.put(UifParameters.METHOD_TO_CALL, newMethodToCall);
870 props.put(UifParameters.VIEW_ID, form.getViewId());
871 props.put(UifParameters.FORM_KEY, form.getFormKey());
872 props.put(UifParameters.AJAX_REQUEST, "false");
873
874 return performRedirect(form, form.getFormPostUrl(), props);
875 }
876
877
878
879
880
881
882
883
884
885
886
887 protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) {
888 String redirectUrl = UrlFactory.parameterizeUrl(baseUrl, urlParameters);
889
890 return performRedirect(form, redirectUrl);
891 }
892
893
894
895
896
897
898
899
900 protected ModelAndView performRedirect(UifFormBase form, String redirectUrl) {
901
902 form.setRequestRedirected(true);
903
904
905 form.setAjaxReturnType(UifConstants.AjaxReturnTypes.REDIRECT.getKey());
906
907 ModelAndView modelAndView;
908 if (form.isAjaxRequest()) {
909 modelAndView = getUIFModelAndView(form, form.getPageId());
910 modelAndView.addObject("redirectUrl", redirectUrl);
911 } else {
912 modelAndView = new ModelAndView(UifConstants.REDIRECT_PREFIX + redirectUrl);
913 }
914
915 return modelAndView;
916 }
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932 protected ModelAndView getMessageView(UifFormBase form, String headerText, String messageText) {
933
934 MessageView messageView = (MessageView) getViewService().getViewById(UifConstants.MESSAGE_VIEW_ID);
935
936 messageView.setHeaderText(headerText);
937 messageView.setMessageText(messageText);
938
939 form.setViewId(UifConstants.MESSAGE_VIEW_ID);
940 form.setView(messageView);
941
942 return getUIFModelAndView(form);
943 }
944
945
946
947
948 @MethodAccessible
949 @RequestMapping(params = "methodToCall=retrieveCollectionPage")
950 public ModelAndView retrieveCollectionPage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
951 HttpServletRequest request, HttpServletResponse response) throws Exception {
952 form.setCollectionPagingRequest(true);
953
954 return getUIFModelAndView(form);
955 }
956
957
958
959
960
961
962
963 @MethodAccessible
964 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=tableJsonRetrieval")
965 public ModelAndView tableJsonRetrieval(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
966 HttpServletRequest request, HttpServletResponse response) {
967 form.setCollectionPagingRequest(true);
968
969
970 form.setRequestJsonTemplate(UifConstants.TableToolsValues.JSON_TEMPLATE);
971
972 return getUIFModelAndView(form);
973 }
974
975
976
977
978
979
980
981
982 protected ModelAndView getUIFModelAndView(UifFormBase form) {
983 return getUIFModelAndView(form, form.getPageId());
984 }
985
986
987
988
989
990
991
992
993
994
995 protected ModelAndView getUIFModelAndView(UifFormBase form, String pageId) {
996 return UifControllerHelper.getUIFModelAndView(form, pageId);
997 }
998
999
1000
1001
1002
1003
1004
1005
1006
1007 protected ModelAndView getUIFModelAndViewWithInit(UifFormBase form, String viewId) {
1008 View view = getViewService().getViewById(viewId);
1009
1010 Assert.notNull(view, "View not found with id: " + viewId);
1011
1012 form.setView(view);
1013 form.setViewId(viewId);
1014
1015 return UifControllerHelper.getUIFModelAndView(form, form.getPageId());
1016 }
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027 protected ModelAndView getUIFModelAndView(UifFormBase form, Map<String, Object> additionalViewAttributes) {
1028 ModelAndView modelAndView = UifControllerHelper.getUIFModelAndView(form, form.getPageId());
1029
1030 if (additionalViewAttributes != null) {
1031 for (Map.Entry<String, Object> additionalViewAttribute : additionalViewAttributes.entrySet()) {
1032 modelAndView.getModelMap().put(additionalViewAttribute.getKey(), additionalViewAttribute.getValue());
1033 }
1034 }
1035
1036 return modelAndView;
1037 }
1038
1039
1040
1041
1042
1043
1044 protected ViewService getViewService() {
1045 return KRADServiceLocatorWeb.getViewService();
1046 }
1047
1048 }