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.util.GlobalVariables;
026 import org.kuali.rice.krad.web.controller.UifControllerBase;
027 import org.kuali.rice.krad.web.form.UifFormBase;
028 import org.springframework.stereotype.Controller;
029 import org.springframework.validation.BindingResult;
030 import org.springframework.web.bind.annotation.ModelAttribute;
031 import org.springframework.web.bind.annotation.RequestMapping;
032 import org.springframework.web.bind.annotation.RequestMethod;
033 import org.springframework.web.servlet.ModelAndView;
034
035 /**
036 * Controller for the Test UI Page
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 */
040 @Controller
041 @RequestMapping(value = "/uicomponents")
042 public class UifComponentsTestController extends UifControllerBase {
043
044
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, BindingResult result,
057 HttpServletRequest request, HttpServletResponse response) {
058 UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
059
060 return super.start(uiTestForm, result, request, response);
061 }
062
063 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
064 public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
065 HttpServletRequest request, HttpServletResponse response) {
066 KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
067 return getUIFModelAndView(uiTestForm);
068 }
069
070
071 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
072 public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
073 HttpServletRequest request, HttpServletResponse response) {
074
075 return getUIFModelAndView(uiTestForm, "UifCompView-Page1");
076 }
077
078 /**
079 * Handles menu navigation between view pages
080 */
081 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
082 public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
083 HttpServletRequest request, HttpServletResponse response) {
084 String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
085
086 if (pageId.equals("UifCompView-Page8")) {
087 GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
088 GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
089 GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
090 GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
091 GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
092 GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
093 GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
094 GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
095 }
096 // only refreshing page
097 form.setRenderFullView(false);
098
099 return getUIFModelAndView(form, pageId);
100 }
101
102 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
103 public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
104 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
105
106 return updateComponent(uiTestForm, result, request, response);
107 }
108
109 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
110 public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
111 BindingResult result, HttpServletRequest request, HttpServletResponse response) {
112 GlobalVariables.getMessageMap().putError("field45", "serverTestError");
113 GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
114 GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
115 return updateComponent(uiTestForm, result, request, response);
116 }
117
118 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
119 public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
120 BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
121 GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
122 GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
123 GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
124
125 GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
126 GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
127 GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
128
129 GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
130 GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
131 GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
132 return refresh(uiTestForm, result, request, response);
133 }
134 }