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