View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.travel.krad.controller;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.kuali.rice.core.util.type.KualiPercent;
25  import org.kuali.rice.kns.util.GlobalVariables;
26  import org.kuali.rice.kns.web.spring.controller.UifControllerBase;
27  import org.kuali.rice.kns.web.spring.form.UifFormBase;
28  import org.springframework.stereotype.Controller;
29  import org.springframework.validation.BindingResult;
30  import org.springframework.web.bind.annotation.ModelAttribute;
31  import org.springframework.web.bind.annotation.RequestMapping;
32  import org.springframework.web.bind.annotation.RequestMethod;
33  import org.springframework.web.servlet.ModelAndView;
34  
35  import edu.sampleu.travel.bo.FiscalOfficer;
36  import edu.sampleu.travel.bo.TravelAccount;
37  import edu.sampleu.travel.krad.form.UITestForm;
38  
39  /**
40   * Controller for the Test UI Page
41   * 
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  @Controller
45  @RequestMapping(value = "/uitest")
46  public class UITestController extends UifControllerBase {
47  
48  	@Override
49      protected UITestForm createInitialForm(HttpServletRequest request) {
50          return new UITestForm();
51      }
52  
53  	@Override
54  	@RequestMapping(params = "methodToCall=start")
55  	public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
56  			HttpServletRequest request, HttpServletResponse response) {
57  	    UITestForm uiTestForm = (UITestForm) form;
58  		
59  		// populate model for testing
60  		TravelAccount travelAccount = new TravelAccount();
61  		travelAccount.setNumber("101");
62  		travelAccount.setName("Account 101");
63  
64  		FiscalOfficer fiscalOfficer = new FiscalOfficer();
65  		fiscalOfficer.setId(new Long(1));
66  
67  		List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
68  
69  		TravelAccount travelAccount2 = new TravelAccount();
70  		travelAccount2.setNumber("102");
71  		travelAccount2.setName("Account 102");
72  		travelAccount2.setSubAccount("34");
73  		travelAccount2.setSubAccountName("G34 So");
74  		travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
75  		officerAccounts.add(travelAccount2);
76  
77  		TravelAccount travelAccount3 = new TravelAccount();
78  		travelAccount3.setNumber("103");
79  		travelAccount3.setName("Account 103");
80  		officerAccounts.add(travelAccount3);
81  
82  		TravelAccount travelAccount4 = new TravelAccount();
83  		travelAccount4.setNumber("104");
84  		travelAccount4.setName("Account 104");
85  		travelAccount4.setSubAccount("i84n");
86  		travelAccount4.setSubAccountName("Supplies");
87  		travelAccount4.setSubsidizedPercent(new KualiPercent(10));
88  		officerAccounts.add(travelAccount4);
89  
90  		fiscalOfficer.setAccounts(officerAccounts);
91  		travelAccount.setFiscalOfficer(fiscalOfficer);
92  		
93  		// build sub-collections
94  		travelAccount2.setFiscalOfficer(fiscalOfficer);
95  		travelAccount3.setFiscalOfficer(fiscalOfficer);
96  		travelAccount4.setFiscalOfficer(fiscalOfficer);
97  
98  		uiTestForm.setTravelAccount1(travelAccount);
99  		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 }