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.servlet.http.HttpServletRequest; 019 import javax.servlet.http.HttpServletResponse; 020 021 import org.kuali.rice.krad.datadictionary.validation.ViewAttributeValueReader; 022 import org.kuali.rice.krad.service.DictionaryValidationService; 023 import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 024 import org.kuali.rice.krad.uif.UifParameters; 025 import org.kuali.rice.krad.uif.component.Component; 026 import org.kuali.rice.krad.uif.container.CollectionGroup; 027 import org.kuali.rice.krad.uif.container.Container; 028 import org.kuali.rice.krad.uif.container.Group; 029 import org.kuali.rice.krad.uif.field.DataField; 030 import org.kuali.rice.krad.uif.field.FieldGroup; 031 import org.kuali.rice.krad.uif.field.InputField; 032 import org.kuali.rice.krad.uif.layout.StackedLayoutManager; 033 import org.kuali.rice.krad.uif.layout.TableLayoutManager; 034 import org.kuali.rice.krad.util.GlobalVariables; 035 import org.kuali.rice.krad.web.controller.UifControllerBase; 036 import org.kuali.rice.krad.web.form.UifFormBase; 037 import org.springframework.stereotype.Controller; 038 import org.springframework.validation.BindingResult; 039 import org.springframework.web.bind.annotation.ModelAttribute; 040 import org.springframework.web.bind.annotation.RequestMapping; 041 import org.springframework.web.bind.annotation.RequestMethod; 042 import org.springframework.web.servlet.ModelAndView; 043 044 import java.beans.PropertyEditor; 045 import java.util.Enumeration; 046 import java.util.List; 047 import java.util.Map; 048 import java.util.Random; 049 050 /** 051 * Controller for the Test UI Page 052 * 053 * @author Kuali Rice Team (rice.collab@kuali.org) 054 */ 055 @Controller 056 @RequestMapping(value = "/uicomponents") 057 public class UifComponentsTestController extends UifControllerBase { 058 059 /** 060 * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest) 061 */ 062 @Override 063 protected UifComponentsTestForm createInitialForm(HttpServletRequest request) { 064 return new UifComponentsTestForm(); 065 } 066 067 @Override 068 @RequestMapping(params = "methodToCall=start") 069 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 070 HttpServletRequest request, HttpServletResponse response) { 071 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form; 072 073 GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome"); 074 075 return super.start(uiTestForm, result, request, response); 076 } 077 078 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save") 079 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 080 HttpServletRequest request, HttpServletResponse response) { 081 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm); 082 return getUIFModelAndView(uiTestForm); 083 } 084 085 086 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close") 087 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result, 088 HttpServletRequest request, HttpServletResponse response) { 089 090 return getUIFModelAndView(uiTestForm, "UifCompView-Page1"); 091 } 092 093 /** 094 * Handles menu navigation between view pages 095 */ 096 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate") 097 public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 098 HttpServletRequest request, HttpServletResponse response) { 099 String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID); 100 101 if (pageId.equals("UifCompView-Page8")) { 102 GlobalVariables.getMessageMap().putError("gField1", "serverTestError"); 103 GlobalVariables.getMessageMap().putError("gField1", "serverTestError2"); 104 GlobalVariables.getMessageMap().putError("gField2", "serverTestError"); 105 GlobalVariables.getMessageMap().putError("gField3", "serverTestError"); 106 GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning"); 107 GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning"); 108 GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo"); 109 GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo"); 110 } 111 // only refreshing page 112 form.setRenderFullView(false); 113 114 return getUIFModelAndView(form, pageId); 115 } 116 117 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup") 118 public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, 119 BindingResult result, HttpServletRequest request, HttpServletResponse response) { 120 121 return getUIFModelAndView(uiTestForm); 122 } 123 124 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages") 125 public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, 126 BindingResult result, HttpServletRequest request, HttpServletResponse response) { 127 GlobalVariables.getMessageMap().putError("field45", "serverTestError"); 128 GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning"); 129 GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo"); 130 131 return getUIFModelAndView(uiTestForm); 132 } 133 134 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages") 135 public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, 136 BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { 137 GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError"); 138 GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning"); 139 GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo"); 140 141 GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError"); 142 GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning"); 143 GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo"); 144 145 GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError"); 146 GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning"); 147 GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo"); 148 return refresh(uiTestForm, result, request, response); 149 } 150 151 152 /** 153 * Adds errors to fields defined in the validationMessageFields array 154 */ 155 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors") 156 public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 157 HttpServletRequest request, HttpServletResponse response) { 158 159 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){ 160 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest"); 161 GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest"); 162 } 163 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){ 164 GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest"); 165 } 166 167 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors(); 168 for(String key: propertyEditors.keySet()){ 169 GlobalVariables.getMessageMap().putError(key, "error1Test"); 170 } 171 172 return getUIFModelAndView(form); 173 } 174 175 /** 176 * Adds warnings to fields defined in the validationMessageFields array 177 */ 178 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings") 179 public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 180 HttpServletRequest request, HttpServletResponse response) { 181 182 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){ 183 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest"); 184 GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest"); 185 } 186 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){ 187 GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest"); 188 } 189 190 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors(); 191 for(String key: propertyEditors.keySet()){ 192 GlobalVariables.getMessageMap().putWarning(key, "warning1Test"); 193 } 194 195 return getUIFModelAndView(form); 196 } 197 198 /** 199 * Adds infos to fields defined in the validationMessageFields array 200 */ 201 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo") 202 public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 203 HttpServletRequest request, HttpServletResponse response) { 204 205 if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){ 206 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest"); 207 GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest"); 208 } 209 else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){ 210 GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest"); 211 } 212 213 Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors(); 214 for(String key: propertyEditors.keySet()){ 215 GlobalVariables.getMessageMap().putInfo(key, "info1Test"); 216 } 217 218 return getUIFModelAndView(form); 219 } 220 221 /** 222 * Adds all message types to fields defined in the validationMessageFields array 223 */ 224 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages") 225 public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 226 HttpServletRequest request, HttpServletResponse response) { 227 228 this.addErrors(form, result, request, response); 229 this.addWarnings(form, result, request, response); 230 this.addInfo(form, result, request, response); 231 232 return getUIFModelAndView(form); 233 } 234 235 /** 236 * Adds error and warning messages to fields defined in the validationMessageFields array 237 */ 238 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages") 239 public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 240 HttpServletRequest request, HttpServletResponse response) { 241 242 this.addErrors(form, result, request, response); 243 this.addWarnings(form, result, request, response); 244 245 return getUIFModelAndView(form); 246 } 247 248 /** 249 * Adds error and info messages to fields defined in the validationMessageFields array 250 */ 251 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages") 252 public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 253 HttpServletRequest request, HttpServletResponse response) { 254 255 this.addErrors(form, result, request, response); 256 this.addInfo(form, result, request, response); 257 258 return getUIFModelAndView(form); 259 } 260 261 /** 262 * Adds warning and info messages to fields defined in the validationMessageFields array 263 */ 264 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarningInfoMessages") 265 public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 266 HttpServletRequest request, HttpServletResponse response) { 267 268 this.addWarnings(form, result, request, response); 269 this.addInfo(form, result, request, response); 270 271 return getUIFModelAndView(form); 272 } 273 274 }