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 edu.sampleu.travel.bo.FiscalOfficer;
19 import edu.sampleu.travel.bo.TravelAccount;
20 import edu.sampleu.travel.krad.form.UITestForm;
21 import org.kuali.rice.core.api.util.type.KualiPercent;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.web.controller.UifControllerBase;
24 import org.kuali.rice.krad.web.form.UifFormBase;
25 import org.springframework.stereotype.Controller;
26 import org.springframework.validation.BindingResult;
27 import org.springframework.web.bind.annotation.ModelAttribute;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RequestMethod;
30 import org.springframework.web.servlet.ModelAndView;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.util.ArrayList;
35 import java.util.List;
36
37
38
39
40
41
42 @Controller
43 @RequestMapping(value = "/uitest")
44 public class UITestController extends UifControllerBase {
45
46 @Override
47 protected UITestForm createInitialForm(HttpServletRequest request) {
48 return new UITestForm();
49 }
50
51 @Override
52 @RequestMapping(params = "methodToCall=start")
53 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
54 HttpServletRequest request, HttpServletResponse response) {
55 UITestForm uiTestForm = (UITestForm) form;
56
57
58 TravelAccount travelAccount = new TravelAccount();
59 travelAccount.setNumber("101");
60 travelAccount.setName("Account 101");
61
62 FiscalOfficer fiscalOfficer = new FiscalOfficer();
63 fiscalOfficer.setId(new Long(1));
64 FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
65 fiscalOfficer.setId(new Long(1));
66 FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
67 fiscalOfficer.setId(new Long(1));
68 FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
69 fiscalOfficer.setId(new Long(1));
70
71
72 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
73
74 TravelAccount travelAccount2 = new TravelAccount();
75 travelAccount2.setNumber("102");
76 travelAccount2.setName("Account 102");
77 travelAccount2.setSubAccount("34");
78 travelAccount2.setSubAccountName("G34 So");
79 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
80 officerAccounts.add(travelAccount2);
81
82 TravelAccount travelAccount3 = new TravelAccount();
83 travelAccount3.setNumber("103");
84 travelAccount3.setName("Account 103");
85 officerAccounts.add(travelAccount3);
86
87 TravelAccount travelAccount4 = new TravelAccount();
88 travelAccount4.setNumber("104");
89 travelAccount4.setName("Account 104");
90 travelAccount4.setSubAccount("i84n");
91 travelAccount4.setSubAccountName("Supplies");
92 travelAccount4.setSubsidizedPercent(new KualiPercent(10));
93 officerAccounts.add(travelAccount4);
94
95 fiscalOfficer.setAccounts(officerAccounts);
96 travelAccount.setFiscalOfficer(fiscalOfficer);
97
98
99 travelAccount2.setFiscalOfficer(fiscalOfficer2);
100 travelAccount3.setFiscalOfficer(fiscalOfficer3);
101 travelAccount4.setFiscalOfficer(fiscalOfficer4);
102
103 uiTestForm.setTravelAccount1(travelAccount);
104 uiTestForm.setTravelAccount2(travelAccount2);
105 uiTestForm.setTravelAccount3(travelAccount3);
106 uiTestForm.setTravelAccount4(travelAccount4);
107
108 uiTestForm.setField5("a14");
109
110 uiTestForm.setField1("Field1");
111 uiTestForm.setField2("Field2");
112
113 uiTestForm.setHidden1("Hidden1");
114 uiTestForm.setHidden2("Hidden2");
115
116 return super.start(uiTestForm, result, request, response);
117 }
118
119 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
120 public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
121 HttpServletRequest request, HttpServletResponse response) {
122
123 if(uiTestForm.getField2().equals("server_error")){
124 GlobalVariables.getMessageMap().putError("field2", "serverTestError");
125 GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
126 GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
127 GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
128 GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
129 GlobalVariables.getMessageMap().putError("field13", "serverTestError");
130 GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
131 GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
132 GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
133 GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
134 GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
135
136 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), uiTestForm.getPageId());
137 }
138
139 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
140 }
141
142 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
143 public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
144 HttpServletRequest request, HttpServletResponse response) {
145
146 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
147 }
148
149 }