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 @MethodAccessible
162 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
163 public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
164 HttpServletRequest request, HttpServletResponse response) {
165
166 if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
167 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
168 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
169 } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
170 GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
171 } else if (form.getPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
172 GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
173 }
174
175 if (form.getViewPostMetadata().getId().equals("RichMessagesView")) {
176 GlobalVariables.getMessageMap().putError("Demo-BasicMessagesSection", "richValidationMessageTest");
177 GlobalVariables.getMessageMap().putError("field5", "richValidationMessageTest2");
178 }
179
180 Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
181 for (String id : inputFieldIds) {
182 if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
183 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
184 UifConstants.PostMetadata.PATH);
185 GlobalVariables.getMessageMap().putError(key, "error1Test");
186 }
187 }
188
189 return getUIFModelAndView(form);
190 }
191
192
193
194
195 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
196 public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
197 HttpServletRequest request, HttpServletResponse response) {
198
199 if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
200 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
201 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
202 } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
203 GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
204 }
205
206 Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
207 for (String id : inputFieldIds) {
208 if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
209 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
210 UifConstants.PostMetadata.PATH);
211 GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
212 }
213 }
214
215 return getUIFModelAndView(form);
216 }
217
218
219
220
221 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
222 public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
223 HttpServletRequest request, HttpServletResponse response) {
224
225 if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
226 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
227 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
228 } else if (form.getPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
229 GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
230 }
231
232 Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
233 for (String id : inputFieldIds) {
234 if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH) != null) {
235 String key = (String) form.getViewPostMetadata().getComponentPostData(id,
236 UifConstants.PostMetadata.PATH);
237 GlobalVariables.getMessageMap().putInfo(key, "info1Test");
238 }
239 }
240
241 return getUIFModelAndView(form);
242 }
243
244
245
246
247 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
248 public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
249 HttpServletRequest request, HttpServletResponse response) {
250
251 this.addErrors(form, result, request, response);
252 this.addWarnings(form, result, request, response);
253 this.addInfo(form, result, request, response);
254
255 return getUIFModelAndView(form);
256 }
257
258
259
260
261 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
262 public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
263 HttpServletRequest request, HttpServletResponse response) {
264
265 this.addErrors(form, result, request, response);
266 this.addWarnings(form, result, request, response);
267
268 return getUIFModelAndView(form);
269 }
270
271
272
273
274 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
275 public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
276 HttpServletRequest request, HttpServletResponse response) {
277
278 this.addErrors(form, result, request, response);
279 this.addInfo(form, result, request, response);
280
281 return getUIFModelAndView(form);
282 }
283
284
285
286
287 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addSingleErrorMessage")
288 public ModelAndView addSingleErrorMessage(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
289 HttpServletRequest request, HttpServletResponse response) {
290
291 if (form.getPageId().equals("Demo-ValidationLayout-SubSectionsPage")) {
292 GlobalVariables.getMessageMap().putError("Uif-ValidationLayout-SubGroup", "errorSectionTest");
293 } else {
294 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
295 }
296
297 return getUIFModelAndView(form);
298 }
299
300
301
302
303 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnInfoMessages")
304 public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
305 HttpServletRequest request, HttpServletResponse response) {
306
307 this.addWarnings(form, result, request, response);
308 this.addInfo(form, result, request, response);
309
310 return getUIFModelAndView(form);
311 }
312
313 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
314 public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
315 HttpServletRequest request, HttpServletResponse response) {
316
317 KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state2");
318 if (!GlobalVariables.getMessageMap().hasErrors()) {
319 form.setState("state2");
320 }
321
322 return getUIFModelAndView(form);
323 }
324
325 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
326 public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
327 HttpServletRequest request, HttpServletResponse response) {
328
329 KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state3");
330 if (!GlobalVariables.getMessageMap().hasErrors()) {
331 form.setState("state3");
332 }
333
334 return getUIFModelAndView(form);
335 }
336
337 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
338 public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
339 HttpServletRequest request, HttpServletResponse response) {
340
341 KRADServiceLocatorWeb.getViewValidationService().validateView(form, "state4");
342 if (!GlobalVariables.getMessageMap().hasErrors()) {
343 form.setState("state4");
344 }
345
346 return getUIFModelAndView(form);
347 }
348
349
350
351
352
353
354
355
356
357
358 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=errorCheck")
359 public ModelAndView errorCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
360 HttpServletRequest request, HttpServletResponse response) {
361
362 if (true) {
363 throw new RuntimeException("Generate fake incident report");
364 }
365
366 return getUIFModelAndView(form);
367 }
368
369
370
371
372
373
374
375
376
377
378 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
379 public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
380 HttpServletRequest request, HttpServletResponse response) {
381 Properties props = new Properties();
382 props.put(UifParameters.VIEW_ID, form.getViewId());
383 props.put(UifParameters.FORM_KEY, form.getFormKey());
384 return performRedirect(form, "http://localhost:8080/kr-dev", props);
385 }
386
387 @Override
388 public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
389 HttpServletRequest request, HttpServletResponse response) {
390 GlobalVariables.getMessageMap().addGrowlMessage("Greetings!", "kitchenSink.welcome");
391 if (uifForm.getPageId().equals("Demo-ValidationLayout-CollectionsErrorPage")) {
392 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-CollectionErrorSection",
393 "errorSectionTest");
394 GlobalVariables.getMessageMap().putErrorForSectionId("Demo-ValidationLayout-CollectionErrorSection",
395 "errorSectionTest");
396 }
397 return super.addLine(uifForm, result, request, response);
398 }
399
400 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=customLineAction")
401 public ModelAndView customLineAction(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
402 HttpServletRequest request, HttpServletResponse response) {
403
404 String actionParm1 = uifForm.getActionParamaterValue("field1");
405 String actionParm2 = uifForm.getActionParamaterValue("field2");
406
407 GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "actionParms.message", actionParm1,
408 actionParm2);
409
410 return super.deleteLine(uifForm, result, request, response);
411 }
412
413
414
415
416
417
418
419
420
421
422
423 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=updateOfficial")
424 public ModelAndView updateOfficial(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
425 HttpServletRequest request, HttpServletResponse response) {
426
427 String actionParm1 = uifForm.getActionParamaterValue("field1");
428
429 GlobalVariables.getMessageMap().addGrowlMessage("Action Parameters", "customLineAction.message", actionParm1);
430
431 return getUIFModelAndView(uifForm);
432 }
433
434
435
436
437
438
439
440
441
442
443 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeReadOnly")
444 public ModelAndView makeReadOnly(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
445 HttpServletRequest request, HttpServletResponse response) {
446
447 uifForm.getView().setReadOnly(true);
448 return getUIFModelAndView(uifForm);
449 }
450 }