001 /*
002 * Copyright 2007 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 1.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/ecl1.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.travel.krad.controller;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import javax.servlet.http.HttpServletRequest;
022 import javax.servlet.http.HttpServletResponse;
023
024 import org.kuali.rice.core.util.type.KualiPercent;
025 import org.kuali.rice.kns.util.GlobalVariables;
026 import org.kuali.rice.kns.web.spring.controller.UifControllerBase;
027 import org.kuali.rice.kns.web.spring.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 import edu.sampleu.travel.bo.FiscalOfficer;
036 import edu.sampleu.travel.bo.TravelAccount;
037 import edu.sampleu.travel.krad.form.UITestForm;
038
039 /**
040 * Controller for the Test UI Page
041 *
042 * @author Kuali Rice Team (rice.collab@kuali.org)
043 */
044 @Controller
045 @RequestMapping(value = "/uitest")
046 public class UITestController extends UifControllerBase {
047
048 @Override
049 protected UITestForm createInitialForm(HttpServletRequest request) {
050 return new UITestForm();
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 UITestForm uiTestForm = (UITestForm) form;
058
059 // populate model for testing
060 TravelAccount travelAccount = new TravelAccount();
061 travelAccount.setNumber("101");
062 travelAccount.setName("Account 101");
063
064 FiscalOfficer fiscalOfficer = new FiscalOfficer();
065 fiscalOfficer.setId(new Long(1));
066
067 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
068
069 TravelAccount travelAccount2 = new TravelAccount();
070 travelAccount2.setNumber("102");
071 travelAccount2.setName("Account 102");
072 travelAccount2.setSubAccount("34");
073 travelAccount2.setSubAccountName("G34 So");
074 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
075 officerAccounts.add(travelAccount2);
076
077 TravelAccount travelAccount3 = new TravelAccount();
078 travelAccount3.setNumber("103");
079 travelAccount3.setName("Account 103");
080 officerAccounts.add(travelAccount3);
081
082 TravelAccount travelAccount4 = new TravelAccount();
083 travelAccount4.setNumber("104");
084 travelAccount4.setName("Account 104");
085 travelAccount4.setSubAccount("i84n");
086 travelAccount4.setSubAccountName("Supplies");
087 travelAccount4.setSubsidizedPercent(new KualiPercent(10));
088 officerAccounts.add(travelAccount4);
089
090 fiscalOfficer.setAccounts(officerAccounts);
091 travelAccount.setFiscalOfficer(fiscalOfficer);
092
093 // build sub-collections
094 travelAccount2.setFiscalOfficer(fiscalOfficer);
095 travelAccount3.setFiscalOfficer(fiscalOfficer);
096 travelAccount4.setFiscalOfficer(fiscalOfficer);
097
098 uiTestForm.setTravelAccount1(travelAccount);
099 uiTestForm.setTravelAccount2(travelAccount);
100 uiTestForm.setTravelAccount3(travelAccount);
101 uiTestForm.setTravelAccount4(travelAccount);
102
103 uiTestForm.setField5("a14");
104
105 uiTestForm.setField1("Field1");
106 uiTestForm.setField2("Field2");
107
108 return super.start(uiTestForm, result, request, response);
109 }
110
111 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
112 public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
113 HttpServletRequest request, HttpServletResponse response) {
114 //For testing server side errors:
115 if(uiTestForm.getField2().equals("server_error")){
116 GlobalVariables.getMessageMap().putError("field2", "serverTestError");
117 GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
118 GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
119 GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
120 GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
121 GlobalVariables.getMessageMap().putError("field13", "serverTestError");
122 GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
123 GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
124 GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
125 GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
126 GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
127 //GlobalVariables.getMessageMap().clearErrorMessages();
128 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), uiTestForm.getPageId());
129 }
130
131 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page2");
132 }
133
134 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
135 public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
136 HttpServletRequest request, HttpServletResponse response) {
137
138 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
139 }
140
141 }