1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.demo.kitchensink;
17
18 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
19 import org.kuali.rice.krad.uif.UifParameters;
20 import org.kuali.rice.krad.util.GlobalVariables;
21 import org.kuali.rice.krad.web.controller.UifControllerBase;
22 import org.kuali.rice.krad.web.form.UifFormBase;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.validation.BindingResult;
25 import org.springframework.web.bind.annotation.ModelAttribute;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RequestMethod;
28 import org.springframework.web.servlet.ModelAndView;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.beans.PropertyEditor;
33 import java.util.Map;
34 import java.util.Properties;
35
36
37
38
39
40
41 @Controller
42 @RequestMapping(value = "/uicomponents")
43 public class UifComponentsTestController extends UifControllerBase {
44
45
46
47
48 @Override
49 protected UifComponentsTestForm createInitialForm(HttpServletRequest request) {
50 return new UifComponentsTestForm();
51 }
52
53 @Override
54 @RequestMapping(params = "methodToCall=start")
55 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form,
56 HttpServletRequest request, HttpServletResponse response) {
57 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
58 form.setState("state1");
59
60 if (form.getView().getId().equals("UifGeneratedFields")) {
61 for (int i = 0; i < 100; i++) {
62 ((UifComponentsTestForm) form).getList1generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
63 "D" + i));
64 }
65 for (int i = 0; i < 100; i++) {
66 ((UifComponentsTestForm) form).getList2generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
67 "D" + i));
68 }
69 for (int i = 0; i < 10; i++) {
70 ((UifComponentsTestForm) form).getList3generated().add(new UITestObject("A" + i, "B" + i, "C" + i,
71 "D" + i));
72 for (int j = 0; j < 10; j++) {
73 ((UifComponentsTestForm) form).getList3generated().get(i).getSubList().add(new UITestObject(
74 "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j));
75 }
76 }
77 }
78
79 GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome");
80
81 return super.start(uiTestForm, request, response);
82 }
83
84 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
85 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
86 HttpServletRequest request, HttpServletResponse response) {
87 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
88 return getUIFModelAndView(uiTestForm);
89 }
90
91 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
92 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
93 HttpServletRequest request, HttpServletResponse response) {
94
95 return getUIFModelAndView(uiTestForm, "UifCompView-Page1");
96 }
97
98
99
100
101 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
102 public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
103 HttpServletRequest request, HttpServletResponse response) {
104 String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
105
106 if (pageId.equals("UifCompView-Page8")) {
107 GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
108 GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
109 GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
110 GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
111 GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
112 GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
113 GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
114 GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
115 }
116
117 return getUIFModelAndView(form, pageId);
118 }
119
120 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
121 public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
122 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
123
124 return getUIFModelAndView(uiTestForm);
125 }
126
127 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
128 public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
129 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
130 GlobalVariables.getMessageMap().putError("field45", "serverTestError");
131 GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
132 GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
133
134 return getUIFModelAndView(uiTestForm);
135 }
136
137 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
138 public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
139 BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
140 GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
141 GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
142 GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
143
144 GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
145 GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
146 GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
147
148 GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
149 GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
150 GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
151 return refresh(uiTestForm, result, request, response);
152 }
153
154
155
156
157 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
158 public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
159 HttpServletRequest request, HttpServletResponse response) {
160
161 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
162 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
163 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
164 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
165 GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
166 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
167 GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
168 }
169
170 if (form.getPostedView().getId().equals("RichMessagesView")) {
171 GlobalVariables.getMessageMap().putError("Demo-BasicMessagesSection", "richValidationMessageTest");
172 GlobalVariables.getMessageMap().putError("field5", "richValidationMessageTest2");
173 }
174
175 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
176 for (String key : propertyEditors.keySet()) {
177 GlobalVariables.getMessageMap().putError(key, "error1Test");
178 }
179
180 return getUIFModelAndView(form);
181 }
182
183
184
185
186 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
187 public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
188 HttpServletRequest request, HttpServletResponse response) {
189
190 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
191 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
192 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
193 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
194 GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
195 }
196
197 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
198 for (String key : propertyEditors.keySet()) {
199 GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
200 }
201
202 return getUIFModelAndView(form);
203 }
204
205
206
207
208 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
209 public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
210 HttpServletRequest request, HttpServletResponse response) {
211
212 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
213 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
214 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
215 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
216 GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
217 }
218
219 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
220 for (String key : propertyEditors.keySet()) {
221 GlobalVariables.getMessageMap().putInfo(key, "info1Test");
222 }
223
224 return getUIFModelAndView(form);
225 }
226
227
228
229
230 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
231 public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
232 HttpServletRequest request, HttpServletResponse response) {
233
234 this.addErrors(form, result, request, response);
235 this.addWarnings(form, result, request, response);
236 this.addInfo(form, result, request, response);
237
238 return getUIFModelAndView(form);
239 }
240
241
242
243
244 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
245 public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
246 HttpServletRequest request, HttpServletResponse response) {
247
248 this.addErrors(form, result, request, response);
249 this.addWarnings(form, result, request, response);
250
251 return getUIFModelAndView(form);
252 }
253
254
255
256
257 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
258 public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
259 HttpServletRequest request, HttpServletResponse response) {
260
261 this.addErrors(form, result, request, response);
262 this.addInfo(form, result, request, response);
263
264 return getUIFModelAndView(form);
265 }
266
267
268
269
270 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addSingleErrorMessage")
271 public ModelAndView addSingleErrorMessage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
272 HttpServletRequest request, HttpServletResponse response) {
273
274 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
275 GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
276 } else {
277 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
278 }
279
280 return getUIFModelAndView(form);
281 }
282
283
284
285
286 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnInfoMessages")
287 public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
288 HttpServletRequest request, HttpServletResponse response) {
289
290 this.addWarnings(form, result, request, response);
291 this.addInfo(form, result, request, response);
292
293 return getUIFModelAndView(form);
294 }
295
296 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
297 public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
298 HttpServletRequest request, HttpServletResponse response) {
299
300 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state2");
301 if (!GlobalVariables.getMessageMap().hasErrors()) {
302 form.setState("state2");
303 }
304
305 return getUIFModelAndView(form);
306 }
307
308 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
309 public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
310 HttpServletRequest request, HttpServletResponse response) {
311
312 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state3");
313 if (!GlobalVariables.getMessageMap().hasErrors()) {
314 form.setState("state3");
315 }
316
317 return getUIFModelAndView(form);
318 }
319
320 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
321 public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
322 HttpServletRequest request, HttpServletResponse response) {
323
324 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state4");
325 if (!GlobalVariables.getMessageMap().hasErrors()) {
326 form.setState("state4");
327 }
328
329 return getUIFModelAndView(form);
330 }
331
332
333
334
335
336
337
338
339
340
341 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=errorCheck")
342 public ModelAndView errorCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
343 HttpServletRequest request, HttpServletResponse response) {
344
345 if (true) {
346 throw new RuntimeException("Generate fake incident report");
347 }
348
349 return getUIFModelAndView(form);
350 }
351
352
353
354
355
356
357
358
359
360
361 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
362 public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
363 HttpServletRequest request, HttpServletResponse response) {
364 Properties props = new Properties();
365 props.put(UifParameters.VIEW_ID, form.getViewId());
366 props.put(UifParameters.FORM_KEY, form.getFormKey());
367 return performRedirect(form, "http://localhost:8080/kr-dev", props);
368 }
369
370 @Override
371 public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
372 HttpServletRequest request, HttpServletResponse response) {
373 GlobalVariables.getMessageMap().addGrowlMessage("Greetings!", "kitchenSink.welcome");
374 if (uifForm.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-CollectionsErrorPage")) {
375 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-CollectionErrorSection",
376 "errorSectionTest");
377 GlobalVariables.getMessageMap().putErrorForSectionId("Demo-ValidationLayout-CollectionErrorSection",
378 "errorSectionTest");
379 }
380 return super.addLine(uifForm, result, request, response);
381 }
382
383 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=customLineAction")
384 public ModelAndView customLineAction(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
385 HttpServletRequest request, HttpServletResponse response) {
386
387 String actionParm1 = uifForm.getActionParamaterValue("field1");
388 String actionParm2 = uifForm.getActionParamaterValue("field2");
389
390 GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "actionParms.message", actionParm1,
391 actionParm2);
392
393 return super.deleteLine(uifForm, result, request, response);
394 }
395
396
397
398
399
400
401
402
403
404
405 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=updateOfficial")
406 public ModelAndView updateOfficial(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
407 HttpServletRequest request, HttpServletResponse response) {
408
409 String actionParm1 = uifForm.getActionParamaterValue("field1");
410
411 GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "customLineAction.message", actionParm1);
412
413 return getUIFModelAndView(uifForm);
414 }
415
416
417
418
419
420
421
422
423
424
425 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeReadOnly")
426 public ModelAndView makeReadOnly(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
427 HttpServletRequest request, HttpServletResponse response) {
428
429 uifForm.getView().setReadOnly(true);
430 return getUIFModelAndView(uifForm);
431 }
432 }