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