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.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 @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
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 FiscalOfficer fiscalOfficer2 = new FiscalOfficer();
67 fiscalOfficer.setId(new Long(1));
68 FiscalOfficer fiscalOfficer3 = new FiscalOfficer();
69 fiscalOfficer.setId(new Long(1));
70 FiscalOfficer fiscalOfficer4 = new FiscalOfficer();
71 fiscalOfficer.setId(new Long(1));
72
73
74 List<TravelAccount> officerAccounts = new ArrayList<TravelAccount>();
75
76 TravelAccount travelAccount2 = new TravelAccount();
77 travelAccount2.setNumber("102");
78 travelAccount2.setName("Account 102");
79 travelAccount2.setSubAccount("34");
80 travelAccount2.setSubAccountName("G34 So");
81 travelAccount2.setSubsidizedPercent(new KualiPercent(45.0));
82 officerAccounts.add(travelAccount2);
83
84 TravelAccount travelAccount3 = new TravelAccount();
85 travelAccount3.setNumber("103");
86 travelAccount3.setName("Account 103");
87 officerAccounts.add(travelAccount3);
88
89 TravelAccount travelAccount4 = new TravelAccount();
90 travelAccount4.setNumber("104");
91 travelAccount4.setName("Account 104");
92 travelAccount4.setSubAccount("i84n");
93 travelAccount4.setSubAccountName("Supplies");
94 travelAccount4.setSubsidizedPercent(new KualiPercent(10));
95 officerAccounts.add(travelAccount4);
96
97 fiscalOfficer.setAccounts(officerAccounts);
98 travelAccount.setFiscalOfficer(fiscalOfficer);
99
100
101 travelAccount2.setFiscalOfficer(fiscalOfficer2);
102 travelAccount3.setFiscalOfficer(fiscalOfficer3);
103 travelAccount4.setFiscalOfficer(fiscalOfficer4);
104
105 uiTestForm.setTravelAccount1(travelAccount);
106 uiTestForm.setTravelAccount2(travelAccount2);
107 uiTestForm.setTravelAccount3(travelAccount3);
108 uiTestForm.setTravelAccount4(travelAccount4);
109
110 uiTestForm.setField5("a14");
111
112 uiTestForm.setField1("Field1");
113 uiTestForm.setField2("Field2");
114
115 uiTestForm.setHidden1("Hidden1");
116 uiTestForm.setHidden2("Hidden2");
117
118 return super.start(uiTestForm, result, request, response);
119 }
120
121 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
122 public ModelAndView save(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
123 HttpServletRequest request, HttpServletResponse response) {
124
125 if(uiTestForm.getField2().equals("server_error")){
126 GlobalVariables.getMessageMap().putError("field2", "serverTestError");
127 GlobalVariables.getMessageMap().putError("field2", "serverTestError2");
128 GlobalVariables.getMessageMap().putWarning("field2", "serverTestWarning");
129 GlobalVariables.getMessageMap().putInfo("field2", "serverTestInfo");
130 GlobalVariables.getMessageMap().putInfo("field3", "serverTestInfo");
131 GlobalVariables.getMessageMap().putError("field13", "serverTestError");
132 GlobalVariables.getMessageMap().putWarning("field4", "serverTestWarning");
133 GlobalVariables.getMessageMap().putWarning("TEST_WARNING", "serverTestError3");
134 GlobalVariables.getMessageMap().putError("TEST_ERROR", "serverTestError3");
135 GlobalVariables.getMessageMap().putError("vField5", "serverTestError");
136 GlobalVariables.getMessageMap().putError("vField6", "serverTestError");
137
138 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), uiTestForm.getPageId());
139 }
140
141 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page2");
142 }
143
144 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
145 public ModelAndView close(@ModelAttribute("KualiForm") UITestForm uiTestForm, BindingResult result,
146 HttpServletRequest request, HttpServletResponse response) {
147
148 return getUIFModelAndView(uiTestForm, uiTestForm.getViewId(), "page1");
149 }
150
151 }