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