1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.api.util.type.KualiPercent;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.web.controller.UifControllerBase;
27 import org.kuali.rice.krad.web.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
41
42
43
44 @Controller
45 @RequestMapping(value = "/uitest")
46 public class UITestController extends UifControllerBase {
47
48
49
50
51 @Override
52 protected UITestForm createInitialForm() {
53 return new UITestForm();
54 }
55
56 @Override
57 @RequestMapping(params = "methodToCall=start")
58 public ModelAndView start(UifFormBase form) {
59 UITestForm uiTestForm = (UITestForm) form;
60
61
62 TravelAccount travelAccount = new TravelAccount();
63 travelAccount.setNumber("101");
64 travelAccount.setName("Account 101");
65
66 FiscalOfficer fiscalOfficer = new FiscalOfficer();
67 fiscalOfficer.setId(new Long(1));
68 FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
69 fiscalOfficer.setId(new Long(1));
70 FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
71 fiscalOfficer.setId(new Long(1));
72 FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
73 fiscalOfficer.setId(new Long(1));
74
75
76 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
77
78 TravelAccount travelAccount2 = new TravelAccount();
79 travelAccount2.setNumber("102");
80 travelAccount2.setName("Account 102");
81 travelAccount2.setSubAccount("34");
82 travelAccount2.setSubAccountName("G34 So");
83 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
84 officerAccounts.add(travelAccount2);
85
86 TravelAccount travelAccount3 = new TravelAccount();
87 travelAccount3.setNumber("103");
88 travelAccount3.setName("Account 103");
89 officerAccounts.add(travelAccount3);
90
91 TravelAccount travelAccount4 = new TravelAccount();
92 travelAccount4.setNumber("104");
93 travelAccount4.setName("Account 104");
94 travelAccount4.setSubAccount("i84n");
95 travelAccount4.setSubAccountName("Supplies");
96 travelAccount4.setSubsidizedPercent(new KualiPercent(10));
97 officerAccounts.add(travelAccount4);
98
99 fiscalOfficer.setAccounts(officerAccounts);
100 travelAccount.setFiscalOfficer(fiscalOfficer);
101
102
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
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
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
155
156
157
158
159
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
167 bogus.charAt(3);
168
169
170 return getModelAndView(uiTestForm, "page1");
171 }
172
173 }