001 /** 002 * Copyright 2005-2014 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 java.util.Properties; 019 import java.util.Set; 020 021 import javax.servlet.http.HttpServletRequest; 022 import javax.servlet.http.HttpServletResponse; 023 024 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 025 import org.kuali.rice.krad.uif.UifConstants; 026 import org.kuali.rice.krad.uif.UifParameters; 027 import org.kuali.rice.krad.util.GlobalVariables; 028 import org.kuali.rice.krad.web.controller.UifControllerBase; 029 import org.kuali.rice.krad.web.form.UifFormBase; 030 import org.springframework.stereotype.Controller; 031 import org.springframework.validation.BindingResult; 032 import org.springframework.web.bind.annotation.ModelAttribute; 033 import org.springframework.web.bind.annotation.RequestMapping; 034 import org.springframework.web.bind.annotation.RequestMethod; 035 import org.springframework.web.servlet.ModelAndView; 036 037 /** 038 * Controller for the Test UI Page 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 */ 042 @Controller 043 @RequestMapping(value = "/uicomponents") 044 public class UifComponentsTestController extends UifControllerBase { 045 046 /** 047 * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest) 048 */ 049 @Override 050 protected UifComponentsTestForm createInitialForm(HttpServletRequest request) { 051 return new UifComponentsTestForm(); 052 } 053 054 @Override 055 @RequestMapping(params = "methodToCall=start") 056 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, HttpServletRequest request, 057 HttpServletResponse response) { 058 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form; 059 form.setState("state1"); 060 //for generated view: 061 if (form.getView().getId().equals("UifGeneratedFields")) { 062 for (int i = 0; i < 100; i++) { 063 ((UifComponentsTestForm) form).getList1generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 064 "D" + i)); 065 } 066 for (int i = 0; i < 100; i++) { 067 ((UifComponentsTestForm) form).getList2generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 068 "D" + i)); 069 } 070 for (int i = 0; i < 10; i++) { 071 ((UifComponentsTestForm) form).getList3generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 072 "D" + i)); 073 for (int j = 0; j < 10; j++) { 074 ((UifComponentsTestForm) form).getList3generated().get(i).getSubList().add(new UITestObject( 075 "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j)); 076 } 077 } 078 } 079 080 GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome"); 081 082 return super.start(uiTestForm, request, response); 083 } 084 085 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save") 086 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 087 HttpServletRequest request, HttpServletResponse response) { 088 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm); 089 090 return getUIFModelAndView(uiTestForm); 091 } 092 093 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close") 094 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 095 HttpServletRequest request, HttpServletResponse response) { 096 097 return getUIFModelAndView(uiTestForm, "UifCompView-Page1"); 098 } 099 100 /** 101 * Handles menu navigation between view pages 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 * Adds errors to fields defined in the validationMessageFields array 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 * Adds warnings to fields defined in the validationMessageFields array 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 * Adds infos to fields defined in the validationMessageFields array 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 * Adds all message types to fields defined in the validationMessageFields array 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 * Adds error and warning messages to fields defined in the validationMessageFields array 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 * Adds error and info messages to fields defined in the validationMessageFields array 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 * Adds only 1 error message for testing 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 * Adds warning and info messages to fields defined in the validationMessageFields array 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 * Generates a fake incident report to test for errorCallback 348 * 349 * @param form 350 * @param result 351 * @param request 352 * @param response 353 * @return ModelAndView model and view 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 * Test controller method to check for ajax redirect functionality. Redirects to the portal main page 368 * 369 * @param form 370 * @param result 371 * @param request 372 * @param response 373 * @return ModelAndView model and view 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 * Performs custom line action for collection 4 in kitchen sink collection demo. 412 * Just puts out a growl message and returns. 413 * 414 * @param uifForm 415 * @param result 416 * @param request 417 * @param response 418 * @return 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 * Changes the view to readOnly and returns. 433 * 434 * @param uifForm 435 * @param result 436 * @param request 437 * @param response 438 * @return readOnly View 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 //set View to readOnly 444 uifForm.getView().setReadOnly(true); 445 return getUIFModelAndView(uifForm); 446 } 447 }