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.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 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 FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
067 fiscalOfficer.setId(new Long(1));
068 FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
069 fiscalOfficer.setId(new Long(1));
070 FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
071 fiscalOfficer.setId(new Long(1));
072
073
074 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
075
076 TravelAccount travelAccount2 = new TravelAccount();
077 travelAccount2.setNumber("102");
078 travelAccount2.setName("Account 102");
079 travelAccount2.setSubAccount("34");
080 travelAccount2.setSubAccountName("G34 So");
081 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
082 officerAccounts.add(travelAccount2);
083
084 TravelAccount travelAccount3 = new TravelAccount();
085 travelAccount3.setNumber("103");
086 travelAccount3.setName("Account 103");
087 officerAccounts.add(travelAccount3);
088
089 TravelAccount travelAccount4 = new TravelAccount();
090 travelAccount4.setNumber("104");
091 travelAccount4.setName("Account 104");
092 travelAccount4.setSubAccount("i84n");
093 travelAccount4.setSubAccountName("Supplies");
094 travelAccount4.setSubsidizedPercent(new KualiPercent(10));
095 officerAccounts.add(travelAccount4);
096
097 fiscalOfficer.setAccounts(officerAccounts);
098 travelAccount.setFiscalOfficer(fiscalOfficer);
099
100 // build sub-collections
101 travelAccount2.setFiscalOfficer(fiscalOfficer2);
102 travelAccount3.setFiscalOfficer(fiscalOfficer3);
103 travelAccount4.setFiscalOfficer(fiscalOfficer4);
104
105 uiTestForm.setTravelAccount1(travelAccount);
106 uiTestForm.setTravelAccount2(travelAccount2);
107 uiTestForm.setTravelAccount3(travelAccount3);
108 uiTestForm.setTravelAccount4(travelAccount4);
109
110 uiTestForm.setField5("a14");
111
112 uiTestForm.setField1("Field1");
113 uiTestForm.setField2("Field2");
114
115 uiTestForm.setHidden1("Hidden1");
116 uiTestForm.setHidden2("Hidden2");
117
118 return super.start(uiTestForm, result, request, response);
119 }
120
121 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
122 public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
123 HttpServletRequest request, HttpServletResponse response) {
124 //For testing server side errors:
125 if(uiTestForm.getField2().equals("server_error")){
126 GlobalVariables.getMessageMap().putError("field2", "serverTestError");
127 GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
128 GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
129 GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
130 GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
131 GlobalVariables.getMessageMap().putError("field13", "serverTestError");
132 GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
133 GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
134 GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
135 GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
136 GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
137 //GlobalVariables.getMessageMap().clearErrorMessages();
138 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), uiTestForm.getPageId());
139 }
140
141 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page2");
142 }
143
144 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
145 public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
146 HttpServletRequest request, HttpServletResponse response) {
147
148 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
149 }
150
151 }