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, BindingResult result,
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, result, 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 }
167
168 if (form.getPostedView().getId().equals("RichMessagesView")) {
169 GlobalVariables.getMessageMap().putError("Demo-BasicMessagesSection", "richValidationMessageTest");
170 GlobalVariables.getMessageMap().putError("field5", "richValidationMessageTest2");
171 }
172
173 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
174 for (String key : propertyEditors.keySet()) {
175 GlobalVariables.getMessageMap().putError(key, "error1Test");
176 }
177
178 return getUIFModelAndView(form);
179 }
180
181
182
183
184 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
185 public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
186 HttpServletRequest request, HttpServletResponse response) {
187
188 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
189 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
190 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
191 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
192 GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
193 }
194
195 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
196 for (String key : propertyEditors.keySet()) {
197 GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
198 }
199
200 return getUIFModelAndView(form);
201 }
202
203
204
205
206 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
207 public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
208 HttpServletRequest request, HttpServletResponse response) {
209
210 if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")) {
211 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
212 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
213 } else if (form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")) {
214 GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
215 }
216
217 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
218 for (String key : propertyEditors.keySet()) {
219 GlobalVariables.getMessageMap().putInfo(key, "info1Test");
220 }
221
222 return getUIFModelAndView(form);
223 }
224
225
226
227
228 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
229 public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
230 HttpServletRequest request, HttpServletResponse response) {
231
232 this.addErrors(form, result, request, response);
233 this.addWarnings(form, result, request, response);
234 this.addInfo(form, result, request, response);
235
236 return getUIFModelAndView(form);
237 }
238
239
240
241
242 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
243 public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
244 HttpServletRequest request, HttpServletResponse response) {
245
246 this.addErrors(form, result, request, response);
247 this.addWarnings(form, result, request, response);
248
249 return getUIFModelAndView(form);
250 }
251
252
253
254
255 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
256 public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
257 HttpServletRequest request, HttpServletResponse response) {
258
259 this.addErrors(form, result, request, response);
260 this.addInfo(form, result, request, response);
261
262 return getUIFModelAndView(form);
263 }
264
265
266
267
268 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnInfoMessages")
269 public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
270 HttpServletRequest request, HttpServletResponse response) {
271
272 this.addWarnings(form, result, request, response);
273 this.addInfo(form, result, request, response);
274
275 return getUIFModelAndView(form);
276 }
277
278 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
279 public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
280 HttpServletRequest request, HttpServletResponse response) {
281
282 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state2");
283 if (!GlobalVariables.getMessageMap().hasErrors()) {
284 form.setState("state2");
285 }
286
287 return getUIFModelAndView(form);
288 }
289
290 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
291 public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
292 HttpServletRequest request, HttpServletResponse response) {
293
294 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state3");
295 if (!GlobalVariables.getMessageMap().hasErrors()) {
296 form.setState("state3");
297 }
298
299 return getUIFModelAndView(form);
300 }
301
302 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
303 public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
304 HttpServletRequest request, HttpServletResponse response) {
305
306 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state4");
307 if (!GlobalVariables.getMessageMap().hasErrors()) {
308 form.setState("state4");
309 }
310
311 return getUIFModelAndView(form);
312 }
313
314
315
316
317
318
319
320
321
322
323 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=errorCheck")
324 public ModelAndView errorCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
325 HttpServletRequest request, HttpServletResponse response) {
326
327 if (true) {
328 throw new RuntimeException("Generate fake incident report");
329 }
330
331 return getUIFModelAndView(form);
332 }
333
334
335
336
337
338
339
340
341
342
343 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
344 public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
345 HttpServletRequest request, HttpServletResponse response) {
346 Properties props = new Properties();
347 props.put(UifParameters.VIEW_ID, form.getViewId());
348 props.put(UifParameters.FORM_KEY, form.getFormKey());
349 return performRedirect(form, "http://localhost:8080/kr-dev", props);
350 }
351
352 @Override
353 public ModelAndView addLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
354 HttpServletRequest request, HttpServletResponse response) {
355 GlobalVariables.getMessageMap().addGrowlMessage("Greetings!", "kitchenSink.welcome");
356 if (uifForm.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-CollectionsErrorPage")) {
357 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-CollectionErrorSection",
358 "errorSectionTest");
359 GlobalVariables.getMessageMap().putErrorForSectionId("Demo-ValidationLayout-CollectionErrorSection",
360 "errorSectionTest");
361 }
362 return super.addLine(uifForm, result, request, response);
363 }
364 }