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