001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package edu.sampleu.demo.kitchensink;
017
018 import javax.management.RuntimeErrorException;
019 import javax.servlet.http.HttpServletRequest;
020 import javax.servlet.http.HttpServletResponse;
021
022 import org.kuali.rice.krad.datadictionary.validation.ViewAttributeValueReader;
023 import org.kuali.rice.krad.service.DictionaryValidationService;
024 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
025 import org.kuali.rice.krad.uif.UifParameters;
026 import org.kuali.rice.krad.uif.component.Component;
027 import org.kuali.rice.krad.uif.container.CollectionGroup;
028 import org.kuali.rice.krad.uif.container.Container;
029 import org.kuali.rice.krad.uif.container.Group;
030 import org.kuali.rice.krad.uif.field.DataField;
031 import org.kuali.rice.krad.uif.field.FieldGroup;
032 import org.kuali.rice.krad.uif.field.InputField;
033 import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
034 import org.kuali.rice.krad.uif.layout.TableLayoutManager;
035 import org.kuali.rice.krad.util.GlobalVariables;
036 import org.kuali.rice.krad.web.controller.UifControllerBase;
037 import org.kuali.rice.krad.web.form.UifFormBase;
038 import org.springframework.stereotype.Controller;
039 import org.springframework.validation.BindingResult;
040 import org.springframework.web.bind.annotation.ModelAttribute;
041 import org.springframework.web.bind.annotation.RequestMapping;
042 import org.springframework.web.bind.annotation.RequestMethod;
043 import org.springframework.web.servlet.ModelAndView;
044
045 import java.beans.PropertyEditor;
046 import java.util.Enumeration;
047 import java.util.List;
048 import java.util.Map;
049 import java.util.Properties;
050 import java.util.Random;
051
052 /**
053 * Controller for the Test UI Page
054 *
055 * @author Kuali Rice Team (rice.collab@kuali.org)
056 */
057 @Controller
058 @RequestMapping(value = "/uicomponents")
059 public class UifComponentsTestController extends UifControllerBase {
060
061 /**
062 * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
063 */
064 @Override
065 protected UifComponentsTestForm createInitialForm(HttpServletRequest request) {
066 return new UifComponentsTestForm();
067 }
068
069 @Override
070 @RequestMapping(params = "methodToCall=start")
071 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
072 HttpServletRequest request, HttpServletResponse response) {
073 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
074 form.setState("state1");
075 //for generated view:
076 if(form.getView().getId().equals("UifGeneratedFields")){
077 for(int i=0; i<100; i++){
078 ((UifComponentsTestForm)form).getList1generated().add(
079 new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
080 }
081 for(int i=0; i<100; i++){
082 ((UifComponentsTestForm)form).getList2generated().add(
083 new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
084 }
085 for(int i=0; i<10; i++){
086 ((UifComponentsTestForm)form).getList3generated().add(
087 new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
088 for(int j=0; j<10; j++){
089 ((UifComponentsTestForm)form).getList3generated().get(i).getSubList().add(
090 new UITestObject("i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j));
091 }
092 }
093 }
094
095 GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome");
096
097 return super.start(uiTestForm, result, request, response);
098 }
099
100 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
101 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
102 HttpServletRequest request, HttpServletResponse response) {
103 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
104 return getUIFModelAndView(uiTestForm);
105 }
106
107
108 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
109 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
110 HttpServletRequest request, HttpServletResponse response) {
111
112 return getUIFModelAndView(uiTestForm, "UifCompView-Page1");
113 }
114
115 /**
116 * Handles menu navigation between view pages
117 */
118 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
119 public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
120 HttpServletRequest request, HttpServletResponse response) {
121 String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
122
123 if (pageId.equals("UifCompView-Page8")) {
124 GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
125 GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
126 GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
127 GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
128 GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
129 GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
130 GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
131 GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
132 }
133 // only refreshing page
134 form.setRenderFullView(false);
135
136 return getUIFModelAndView(form, pageId);
137 }
138
139 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
140 public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
141 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
142
143 return getUIFModelAndView(uiTestForm);
144 }
145
146 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
147 public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
148 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
149 GlobalVariables.getMessageMap().putError("field45", "serverTestError");
150 GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
151 GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
152
153 return getUIFModelAndView(uiTestForm);
154 }
155
156 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
157 public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
158 BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
159 GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
160 GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
161 GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
162
163 GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
164 GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
165 GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
166
167 GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
168 GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
169 GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
170 return refresh(uiTestForm, result, request, response);
171 }
172
173
174 /**
175 * Adds errors to fields defined in the validationMessageFields array
176 */
177 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
178 public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
179 HttpServletRequest request, HttpServletResponse response) {
180
181 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
182 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
183 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
184 }
185 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
186 GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
187 }
188
189 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
190 for(String key: propertyEditors.keySet()){
191 GlobalVariables.getMessageMap().putError(key, "error1Test");
192 }
193
194 return getUIFModelAndView(form);
195 }
196
197 /**
198 * Adds warnings to fields defined in the validationMessageFields array
199 */
200 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
201 public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
202 HttpServletRequest request, HttpServletResponse response) {
203
204 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
205 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
206 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
207 }
208 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
209 GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
210 }
211
212 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
213 for(String key: propertyEditors.keySet()){
214 GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
215 }
216
217 return getUIFModelAndView(form);
218 }
219
220 /**
221 * Adds infos to fields defined in the validationMessageFields array
222 */
223 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
224 public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
225 HttpServletRequest request, HttpServletResponse response) {
226
227 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
228 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
229 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
230 }
231 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
232 GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
233 }
234
235 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
236 for(String key: propertyEditors.keySet()){
237 GlobalVariables.getMessageMap().putInfo(key, "info1Test");
238 }
239
240 return getUIFModelAndView(form);
241 }
242
243 /**
244 * Adds all message types to fields defined in the validationMessageFields array
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 * Adds error and warning messages to fields defined in the validationMessageFields array
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 * Adds error and info messages to fields defined in the validationMessageFields array
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 * Adds warning and info messages to fields defined in the validationMessageFields array
285 */
286 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarningInfoMessages")
287 public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
288 HttpServletRequest request, HttpServletResponse response) {
289
290 this.addWarnings(form, result, request, response);
291 this.addInfo(form, result, request, response);
292
293 return getUIFModelAndView(form);
294 }
295
296 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
297 public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
298 HttpServletRequest request, HttpServletResponse response) {
299
300 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state2");
301 if(!GlobalVariables.getMessageMap().hasErrors()){
302 form.setState("state2");
303 }
304
305 return getUIFModelAndView(form);
306 }
307
308 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
309 public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
310 HttpServletRequest request, HttpServletResponse response) {
311
312 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state3");
313 if(!GlobalVariables.getMessageMap().hasErrors()){
314 form.setState("state3");
315 }
316
317 return getUIFModelAndView(form);
318 }
319
320 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
321 public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
322 HttpServletRequest request, HttpServletResponse response) {
323
324 KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state4");
325 if(!GlobalVariables.getMessageMap().hasErrors()){
326 form.setState("state4");
327 }
328
329 return getUIFModelAndView(form);
330 }
331
332
333
334 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=successCheck")
335 public ModelAndView successCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
336 HttpServletRequest request, HttpServletResponse response) {
337
338 return getUIFModelAndView(form);
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 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
354 public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
355 HttpServletRequest request, HttpServletResponse response) {
356 Properties props = new Properties();
357 props.put(UifParameters.VIEW_ID, form.getViewId());
358 props.put(UifParameters.FORM_KEY, form.getFormKey());
359 return performRedirect(form, "http://localhost:8080/kr-dev", props);
360 }
361
362
363 }