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 org.kuali.rice.krad.service.KRADServiceLocatorWeb; 019 import org.kuali.rice.krad.uif.UifParameters; 020 import org.kuali.rice.krad.util.GlobalVariables; 021 import org.kuali.rice.krad.web.controller.UifControllerBase; 022 import org.kuali.rice.krad.web.form.UifFormBase; 023 import org.springframework.stereotype.Controller; 024 import org.springframework.validation.BindingResult; 025 import org.springframework.web.bind.annotation.ModelAttribute; 026 import org.springframework.web.bind.annotation.RequestMapping; 027 import org.springframework.web.bind.annotation.RequestMethod; 028 import org.springframework.web.servlet.ModelAndView; 029 030 import javax.servlet.http.HttpServletRequest; 031 import javax.servlet.http.HttpServletResponse; 032 import java.beans.PropertyEditor; 033 import java.util.Map; 034 import java.util.Properties; 035 036 /** 037 * Controller for the Test UI Page 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 */ 041 @Controller 042 @RequestMapping(value = "/uicomponents") 043 public class UifComponentsTestController extends UifControllerBase { 044 045 /** 046 * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest) 047 */ 048 @Override 049 protected UifComponentsTestForm createInitialForm(HttpServletRequest request) { 050 return new UifComponentsTestForm(); 051 } 052 053 @Override 054 @RequestMapping(params = "methodToCall=start") 055 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 056 HttpServletRequest request, HttpServletResponse response) { 057 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form; 058 form.setState("state1"); 059 //for generated view: 060 if (form.getView().getId().equals("UifGeneratedFields")) { 061 for (int i = 0; i < 100; i++) { 062 ((UifComponentsTestForm) form).getList1generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 063 "D" + i)); 064 } 065 for (int i = 0; i < 100; i++) { 066 ((UifComponentsTestForm) form).getList2generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 067 "D" + i)); 068 } 069 for (int i = 0; i < 10; i++) { 070 ((UifComponentsTestForm) form).getList3generated().add(new UITestObject("A" + i, "B" + i, "C" + i, 071 "D" + i)); 072 for (int j = 0; j < 10; j++) { 073 ((UifComponentsTestForm) form).getList3generated().get(i).getSubList().add(new UITestObject( 074 "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j)); 075 } 076 } 077 } 078 079 GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome"); 080 081 return super.start(uiTestForm, result, request, response); 082 } 083 084 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save") 085 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 086 HttpServletRequest request, HttpServletResponse response) { 087 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm); 088 return getUIFModelAndView(uiTestForm); 089 } 090 091 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close") 092 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 093 HttpServletRequest request, HttpServletResponse response) { 094 095 return getUIFModelAndView(uiTestForm, "UifCompView-Page1"); 096 } 097 098 /** 099 * Handles menu navigation between view pages 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 * Adds errors to fields defined in the validationMessageFields array 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 * Adds warnings to fields defined in the validationMessageFields array 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 * Adds infos to fields defined in the validationMessageFields array 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 * Adds all message types to fields defined in the validationMessageFields array 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 * Adds error and warning messages to fields defined in the validationMessageFields array 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 * Adds error and info messages to fields defined in the validationMessageFields array 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 * Adds warning and info messages to fields defined in the validationMessageFields array 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 * Generates a fake incident report to test for errorCallback 316 * 317 * @param form 318 * @param result 319 * @param request 320 * @param response 321 * @return ModelAndView model and view 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 * Test controller method to check for ajax redirect functionality. Redirects to the portal main page 336 * 337 * @param form 338 * @param result 339 * @param request 340 * @param response 341 * @return ModelAndView model and view 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 }