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.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.api.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 /** 049 * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest) 050 */ 051 @Override 052 protected UITestForm createInitialForm(HttpServletRequest request) { 053 return new UITestForm(); 054 } 055 056 @Override 057 @RequestMapping(params = "methodToCall=start") 058 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 059 HttpServletRequest request, HttpServletResponse response) { 060 UITestForm uiTestForm = (UITestForm) form; 061 062 // populate model for testing 063 TravelAccount travelAccount = new TravelAccount(); 064 travelAccount.setNumber("101"); 065 travelAccount.setName("Account 101"); 066 067 FiscalOfficer fiscalOfficer = new FiscalOfficer(); 068 fiscalOfficer.setId(new Long(1)); 069 FiscalOfficer fiscalOfficer2 = new FiscalOfficer(); 070 fiscalOfficer.setId(new Long(1)); 071 FiscalOfficer fiscalOfficer3 = new FiscalOfficer(); 072 fiscalOfficer.setId(new Long(1)); 073 FiscalOfficer fiscalOfficer4 = new FiscalOfficer(); 074 fiscalOfficer.setId(new Long(1)); 075 076 077 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>(); 078 079 TravelAccount travelAccount2 = new TravelAccount(); 080 travelAccount2.setNumber("102"); 081 travelAccount2.setName("Account 102"); 082 travelAccount2.setSubAccount("34"); 083 travelAccount2.setSubAccountName("G34 So"); 084 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0)); 085 officerAccounts.add(travelAccount2); 086 087 TravelAccount travelAccount3 = new TravelAccount(); 088 travelAccount3.setNumber("103"); 089 travelAccount3.setName("Account 103"); 090 officerAccounts.add(travelAccount3); 091 092 TravelAccount travelAccount4 = new TravelAccount(); 093 travelAccount4.setNumber("104"); 094 travelAccount4.setName("Account 104"); 095 travelAccount4.setSubAccount("i84n"); 096 travelAccount4.setSubAccountName("Supplies"); 097 travelAccount4.setSubsidizedPercent(new KualiPercent(10)); 098 officerAccounts.add(travelAccount4); 099 100 fiscalOfficer.setAccounts(officerAccounts); 101 travelAccount.setFiscalOfficer(fiscalOfficer); 102 103 // build sub-collections 104 travelAccount2.setFiscalOfficer(fiscalOfficer2); 105 travelAccount3.setFiscalOfficer(fiscalOfficer3); 106 travelAccount4.setFiscalOfficer(fiscalOfficer4); 107 108 uiTestForm.setTravelAccount1(travelAccount); 109 uiTestForm.setTravelAccount2(travelAccount2); 110 uiTestForm.setTravelAccount3(travelAccount3); 111 uiTestForm.setTravelAccount4(travelAccount4); 112 113 uiTestForm.setField5("a14"); 114 115 uiTestForm.setField1("Field1"); 116 uiTestForm.setField2("Field2"); 117 118 uiTestForm.setHidden1("Hidden1"); 119 uiTestForm.setHidden2("Hidden2"); 120 121 return super.start(uiTestForm, result, request, response); 122 } 123 124 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save") 125 public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result, 126 HttpServletRequest request, HttpServletResponse response) { 127 //For testing server side errors: 128 if(uiTestForm.getField2().equals("server_error")){ 129 GlobalVariables.getMessageMap().putError("field2", "serverTestError"); 130 GlobalVariables.getMessageMap().putError("field2", "serverTestError2"); 131 GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning"); 132 GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo"); 133 GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo"); 134 GlobalVariables.getMessageMap().putError("field13", "serverTestError"); 135 GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning"); 136 GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3"); 137 GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3"); 138 GlobalVariables.getMessageMap().putError("vField5", "serverTestError"); 139 GlobalVariables.getMessageMap().putError("vField6", "serverTestError"); 140 //GlobalVariables.getMessageMap().clearErrorMessages(); 141 return getUIFModelAndView(uiTestForm, uiTestForm.getPageId()); 142 } 143 144 return getUIFModelAndView(uiTestForm, "page1"); 145 } 146 147 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close") 148 public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result, 149 HttpServletRequest request, HttpServletResponse response) { 150 151 return getUIFModelAndView(uiTestForm, "page1"); 152 } 153 154 /** 155 * The bogus method generates a NPE. It is used to test incident reporting 156 * @param uiTestForm 157 * @param result 158 * @param request 159 * @param response 160 * @return 161 */ 162 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=foo") 163 public ModelAndView foo(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result, 164 HttpServletRequest request, HttpServletResponse response) { 165 166 String bogus = null; 167 // intentially generate a null pointer error 168 bogus.charAt(3); 169 170 // should never get here 171 return getUIFModelAndView(uiTestForm, "page1"); 172 } 173 174 }