1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.codehaus.jackson.map.ObjectMapper;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.UifParameters;
23 import org.kuali.rice.krad.uif.util.SessionTransient;
24 import org.kuali.rice.krad.uif.view.DialogManager;
25 import org.kuali.rice.krad.uif.view.History;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.uif.service.ViewService;
28 import org.kuali.rice.krad.uif.view.ViewModel;
29 import org.kuali.rice.krad.util.KRADUtils;
30 import org.springframework.web.multipart.MultipartFile;
31 import org.kuali.rice.krad.uif.UifConstants.ViewType;
32
33 import javax.servlet.http.HttpServletRequest;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import java.util.Properties;
40 import java.util.Set;
41 import java.util.UUID;
42
43
44
45
46
47
48
49
50
51
52
53 public class UifFormBase implements ViewModel {
54 private static final long serialVersionUID = 8432543267099454434L;
55
56
57
58 protected String viewId;
59
60 protected String viewName;
61
62 protected ViewType viewTypeName;
63
64 protected String pageId;
65
66 protected String methodToCall;
67
68 protected String formKey;
69
70 @SessionTransient
71 protected String jumpToId;
72
73 @SessionTransient
74 protected String jumpToName;
75
76 @SessionTransient
77 protected String focusId;
78
79 protected String formPostUrl;
80
81 protected String state;
82
83 protected boolean defaultsApplied;
84
85 protected boolean validateDirty;
86
87 protected boolean renderedInLightBox;
88
89 @SessionTransient
90 protected String growlScript;
91
92 @SessionTransient
93 protected String lightboxScript;
94
95 protected View view;
96
97 protected View postedView;
98
99 protected Map<String, String> viewRequestParameters;
100
101 protected List<String> readOnlyFieldsList;
102
103 protected Map<String, Object> newCollectionLines;
104
105 @SessionTransient
106 protected Map<String, String> actionParameters;
107
108 @SessionTransient
109 protected Map<String, Object> clientStateForSyncing;
110
111 @SessionTransient
112 protected Map<String, Set<String>> selectedCollectionLines;
113
114 private List<Object> addedCollectionItems;
115
116 protected MultipartFile attachmentFile;
117
118
119
120 protected String returnLocation;
121
122 protected String returnFormKey;
123
124 @SessionTransient
125 protected boolean ajaxRequest;
126
127 @SessionTransient
128 protected String ajaxReturnType;
129
130
131 protected History formHistory;
132
133
134 @SessionTransient
135 protected String dialogExplanation;
136
137 @SessionTransient
138 protected String dialogResponse;
139
140 private DialogManager dialogManager;
141
142 @SessionTransient
143 protected boolean skipViewInit;
144
145 @SessionTransient
146 protected boolean requestRedirect;
147
148 @SessionTransient
149 protected String updateComponentId;
150
151 @SessionTransient
152 protected boolean renderFullView;
153
154 public UifFormBase() {
155 formKey = generateFormKey();
156 renderFullView = true;
157 defaultsApplied = false;
158 renderedInLightBox = false;
159 skipViewInit = false;
160 requestRedirect = false;
161
162 readOnlyFieldsList = new ArrayList<String>();
163 viewRequestParameters = new HashMap<String, String>();
164 newCollectionLines = new HashMap<String, Object>();
165 actionParameters = new HashMap<String, String>();
166 clientStateForSyncing = new HashMap<String, Object>();
167 selectedCollectionLines = new HashMap<String, Set<String>>();
168 addedCollectionItems = new ArrayList();
169 dialogManager = new DialogManager();
170 }
171
172
173
174
175
176
177
178 protected String generateFormKey() {
179 return UUID.randomUUID().toString();
180 }
181
182
183
184
185 @Override
186 public void postBind(HttpServletRequest request) {
187
188 formPostUrl = request.getRequestURL().toString();
189
190
191 if (request.getParameterMap().containsKey(UifParameters.CLIENT_VIEW_STATE)) {
192 String clientStateJSON = request.getParameter(UifParameters.CLIENT_VIEW_STATE);
193 if (StringUtils.isNotBlank(clientStateJSON)) {
194
195 clientStateJSON = StringUtils.replace(clientStateJSON, "'", "\"");
196
197 ObjectMapper mapper = new ObjectMapper();
198 try {
199 clientStateForSyncing = mapper.readValue(clientStateJSON, Map.class);
200 } catch (IOException e) {
201 throw new RuntimeException("Unable to decode client side state JSON", e);
202 }
203 }
204 }
205
206
207 if (request.getParameter(UifParameters.READ_ONLY_FIELDS) != null) {
208 String readOnlyFields = request.getParameter(UifParameters.READ_ONLY_FIELDS);
209 setReadOnlyFieldsList(KRADUtils.convertStringParameterToList(readOnlyFields));
210 }
211
212
213 if (!request.getParameterMap().containsKey(UifParameters.SKIP_VIEW_INIT)) {
214 skipViewInit = false;
215 }
216 }
217
218
219
220
221 @Override
222 public String getViewId() {
223 return this.viewId;
224 }
225
226
227
228
229 @Override
230 public void setViewId(String viewId) {
231 this.viewId = viewId;
232 }
233
234
235
236
237 @Override
238 public String getViewName() {
239 return this.viewName;
240 }
241
242
243
244
245 @Override
246 public void setViewName(String viewName) {
247 this.viewName = viewName;
248 }
249
250
251
252
253 @Override
254 public ViewType getViewTypeName() {
255 return this.viewTypeName;
256 }
257
258
259
260
261 @Override
262 public void setViewTypeName(ViewType viewTypeName) {
263 this.viewTypeName = viewTypeName;
264 }
265
266
267
268
269 @Override
270 public String getPageId() {
271 return this.pageId;
272 }
273
274
275
276
277 @Override
278 public void setPageId(String pageId) {
279 this.pageId = pageId;
280 }
281
282
283
284
285 @Override
286 public String getFormPostUrl() {
287 return this.formPostUrl;
288 }
289
290
291
292
293 @Override
294 public void setFormPostUrl(String formPostUrl) {
295 this.formPostUrl = formPostUrl;
296 }
297
298 public String getReturnLocation() {
299 return this.returnLocation;
300 }
301
302 public void setReturnLocation(String returnLocation) {
303 this.returnLocation = returnLocation;
304 }
305
306 public String getReturnFormKey() {
307 return this.returnFormKey;
308 }
309
310 public void setReturnFormKey(String returnFormKey) {
311 this.returnFormKey = returnFormKey;
312 }
313
314
315
316
317
318
319
320
321 public String getMethodToCall() {
322 return this.methodToCall;
323 }
324
325
326
327
328
329
330 public void setMethodToCall(String methodToCall) {
331 this.methodToCall = methodToCall;
332 }
333
334
335
336
337 @Override
338 public Map<String, String> getViewRequestParameters() {
339 return this.viewRequestParameters;
340 }
341
342
343
344
345 @Override
346 public void setViewRequestParameters(Map<String, String> viewRequestParameters) {
347 this.viewRequestParameters = viewRequestParameters;
348 }
349
350
351
352
353 @Override
354 public List<String> getReadOnlyFieldsList() {
355 return readOnlyFieldsList;
356 }
357
358
359
360
361 @Override
362 public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
363 this.readOnlyFieldsList = readOnlyFieldsList;
364 }
365
366
367
368
369 @Override
370 public Map<String, Object> getNewCollectionLines() {
371 return this.newCollectionLines;
372 }
373
374
375
376
377 @Override
378 public void setNewCollectionLines(Map<String, Object> newCollectionLines) {
379 this.newCollectionLines = newCollectionLines;
380 }
381
382
383
384
385 @Override
386 public Map<String, String> getActionParameters() {
387 return this.actionParameters;
388 }
389
390
391
392
393
394
395 public Properties getActionParametersAsProperties() {
396 return KRADUtils.convertMapToProperties(actionParameters);
397 }
398
399
400
401
402 @Override
403 public void setActionParameters(Map<String, String> actionParameters) {
404 this.actionParameters = actionParameters;
405 }
406
407
408
409
410
411
412
413
414 public String getActionParamaterValue(String actionParameterName) {
415 if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) {
416 return actionParameters.get(actionParameterName);
417 }
418
419 return "";
420 }
421
422
423
424
425
426
427
428
429
430
431
432
433
434 public String getActionEvent() {
435 if ((actionParameters != null) && actionParameters.containsKey(UifConstants.UrlParams.ACTION_EVENT)) {
436 return actionParameters.get(UifConstants.UrlParams.ACTION_EVENT);
437 }
438
439 return "";
440 }
441
442
443
444
445 @Override
446 public Map<String, Object> getClientStateForSyncing() {
447 return clientStateForSyncing;
448 }
449
450
451
452
453 @Override
454 public Map<String, Set<String>> getSelectedCollectionLines() {
455 return selectedCollectionLines;
456 }
457
458
459
460
461 @Override
462 public void setSelectedCollectionLines(Map<String, Set<String>> selectedCollectionLines) {
463 this.selectedCollectionLines = selectedCollectionLines;
464 }
465
466
467
468
469
470
471
472
473
474
475
476
477 public String getFormKey() {
478 return this.formKey;
479 }
480
481
482
483
484
485
486 public void setFormKey(String formKey) {
487 this.formKey = formKey;
488 }
489
490
491
492
493 @Override
494 public boolean isDefaultsApplied() {
495 return this.defaultsApplied;
496 }
497
498
499
500
501 @Override
502 public void setDefaultsApplied(boolean defaultsApplied) {
503 this.defaultsApplied = defaultsApplied;
504 }
505
506
507
508
509
510
511 public boolean isSkipViewInit() {
512 return skipViewInit;
513 }
514
515
516
517
518
519
520 public void setSkipViewInit(boolean skipViewInit) {
521 this.skipViewInit = skipViewInit;
522 }
523
524
525
526
527
528
529 public boolean isRequestRedirect() {
530 return requestRedirect;
531 }
532
533
534
535
536
537
538 public void setRequestRedirect(boolean requestRedirect) {
539 this.requestRedirect = requestRedirect;
540 }
541
542
543
544
545
546
547 public MultipartFile getAttachmentFile() {
548 return this.attachmentFile;
549 }
550
551
552
553
554
555
556 public void setAttachmentFile(MultipartFile attachmentFile) {
557 this.attachmentFile = attachmentFile;
558 }
559
560
561
562
563
564
565 public String getUpdateComponentId() {
566 return updateComponentId;
567 }
568
569
570
571
572
573
574 public void setUpdateComponentId(String updateComponentId) {
575 this.updateComponentId = updateComponentId;
576 }
577
578
579
580
581
582
583
584 public boolean isRenderFullView() {
585 return this.renderFullView;
586 }
587
588
589
590
591
592
593 public void setRenderFullView(boolean renderFullView) {
594 this.renderFullView = renderFullView;
595 }
596
597
598
599
600 @Override
601 public View getView() {
602 return this.view;
603 }
604
605
606
607
608 @Override
609 public void setView(View view) {
610 this.view = view;
611 }
612
613
614
615
616 @Override
617 public View getPostedView() {
618 return this.postedView;
619 }
620
621
622
623
624 @Override
625 public void setPostedView(View postedView) {
626 this.postedView = postedView;
627 }
628
629
630
631
632
633
634
635 protected ViewService getViewService() {
636 return KRADServiceLocatorWeb.getViewService();
637 }
638
639
640
641
642
643
644
645
646
647 public String getJumpToId() {
648 return this.jumpToId;
649 }
650
651
652
653
654 public void setJumpToId(String jumpToId) {
655 this.jumpToId = jumpToId;
656 }
657
658
659
660
661
662
663
664
665 public String getJumpToName() {
666 return this.jumpToName;
667 }
668
669
670
671
672 public void setJumpToName(String jumpToName) {
673 this.jumpToName = jumpToName;
674 }
675
676
677
678
679
680
681
682 public String getFocusId() {
683 return this.focusId;
684 }
685
686
687
688
689 public void setFocusId(String focusId) {
690 this.focusId = focusId;
691 }
692
693
694
695
696
697
698
699
700
701
702
703
704 public History getFormHistory() {
705 return formHistory;
706 }
707
708
709
710
711
712
713 public void setFormHistory(History history) {
714 this.formHistory = history;
715 }
716
717
718
719
720
721
722
723
724
725
726
727
728
729 public boolean isValidateDirty() {
730 return this.validateDirty;
731 }
732
733
734
735
736
737
738 public void setValidateDirty(boolean validateDirty) {
739 this.validateDirty = validateDirty;
740 }
741
742
743
744
745
746
747
748
749
750
751
752
753 public boolean isRenderedInLightBox() {
754 return this.renderedInLightBox;
755 }
756
757
758
759
760
761
762 public void setRenderedInLightBox(boolean renderedInLightBox) {
763 this.renderedInLightBox = renderedInLightBox;
764 }
765
766
767
768
769 @Override
770 public String getGrowlScript() {
771 return growlScript;
772 }
773
774
775
776
777 @Override
778 public void setGrowlScript(String growlScript) {
779 this.growlScript = growlScript;
780 }
781
782
783
784
785 public String getState() {
786 return state;
787 }
788
789
790
791
792 public void setState(String state) {
793 this.state = state;
794 }
795
796
797
798
799 @Override
800 public String getLightboxScript() {
801 return lightboxScript;
802 }
803
804
805
806
807 @Override
808 public void setLightboxScript(String lightboxScript) {
809 this.lightboxScript = lightboxScript;
810 }
811
812
813
814
815 @Override
816 public boolean isAjaxRequest() {
817 return ajaxRequest;
818 }
819
820
821
822
823 @Override
824 public void setAjaxRequest(boolean ajaxRequest) {
825 this.ajaxRequest = ajaxRequest;
826 }
827
828
829
830
831 @Override
832 public String getAjaxReturnType() {
833 return ajaxReturnType;
834 }
835
836
837
838
839
840 @Override
841 public void setAjaxReturnType(String ajaxReturnType) {
842 this.ajaxReturnType = ajaxReturnType;
843 }
844
845
846
847
848
849
850
851
852
853
854 public String getDialogExplanation() {
855 return dialogExplanation;
856 }
857
858
859
860
861
862
863 public void setDialogExplanation(String dialogExplanation) {
864 this.dialogExplanation = dialogExplanation;
865 }
866
867
868
869
870
871
872
873
874
875
876
877 public String getDialogResponse() {
878 return dialogResponse;
879 }
880
881
882
883
884
885
886 public void setDialogResponse(String dialogResponse) {
887 this.dialogResponse = dialogResponse;
888 }
889
890
891
892
893
894
895
896
897
898 public DialogManager getDialogManager() {
899 return dialogManager;
900 }
901
902
903
904
905
906
907 public void setDialogManager(DialogManager dialogManager) {
908 this.dialogManager = dialogManager;
909 }
910
911
912
913
914
915
916
917
918
919
920
921 public List getAddedCollectionItems() {
922 return addedCollectionItems;
923 }
924
925
926
927
928
929
930 public void setAddedCollectionItems(List addedCollectionItems) {
931 this.addedCollectionItems = addedCollectionItems;
932 }
933
934
935
936
937
938
939
940
941
942
943
944
945 public boolean isAddedCollectionItem(Object item) {
946 return addedCollectionItems.contains(item);
947 }
948
949 }