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