1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.demo.kitchensink;
17
18 import org.kuali.rice.krad.uif.view.DialogManager;
19 import org.kuali.rice.krad.web.controller.UifControllerBase;
20 import org.kuali.rice.krad.web.form.UifFormBase;
21 import org.springframework.stereotype.Controller;
22 import org.springframework.validation.BindingResult;
23 import org.springframework.web.bind.annotation.ModelAttribute;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.servlet.ModelAndView;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30
31
32
33
34
35 @Controller
36 @RequestMapping(value = "/dialog-configuration-test")
37 public class DialogTestViewUifController extends UifControllerBase {
38
39 @Override
40 protected UifFormBase createInitialForm(HttpServletRequest request) {
41 return new UifDialogTestForm();
42 }
43
44
45
46
47 @Override
48 @RequestMapping(params = "methodToCall=start")
49 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
50 HttpServletRequest request, HttpServletResponse response) {
51 return super.start(form, result, request, response);
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 @RequestMapping(params = "methodToCall=save")
74 public ModelAndView save(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
75 HttpServletRequest request, HttpServletResponse response) throws Exception {
76 ModelAndView mv;
77
78
79 String dialog1 = "chooseAuthorDialog";
80 String dialog2a = "chooseEastmanBookDialog";
81 String dialog2b = "chooseSeussBookDialog";
82 String dialog3 = "myRestart";
83
84
85 boolean whichAuthor = false;
86 String chosenBook;
87 boolean doRestart = false;
88
89
90 if (!hasDialogBeenAnswered(dialog1, form)){
91
92 return showDialog(dialog1, form, request, response);
93 }
94 whichAuthor = getBooleanDialogResponse(dialog1, form, request, response);
95
96
97 if (whichAuthor){
98 form.setField1("You Selected: P.D. Eastman");
99
100
101 if (!hasDialogBeenAnswered(dialog2a,form)){
102
103 return showDialog(dialog2a, form, request, response);
104 }
105 chosenBook = form.getDialogManager().getDialogExplanation(dialog2a);
106
107
108 form.setField1("You selected: "+chosenBook+" by P.D. Eastman. Here we go...");
109 } else {
110 form.setField1("You Selected: Dr. Seuss");
111
112
113
114 if (!hasDialogBeenDisplayed(dialog2b, form)){
115 form.getDialogManager().addDialog(dialog2b, form.getMethodToCall());
116 return getUIFModelAndView(form, "DialogView-Page1");
117 }
118
119
120 if (!hasDialogBeenAnswered(dialog2b, form)){
121 return showDialog(dialog2b, form, request, response);
122 }
123 chosenBook = form.getDialogManager().getDialogExplanation(dialog2b);
124
125
126 form.setField1("You selected: "+chosenBook+" by Dr. Seuss. Here we go...");
127 }
128
129
130 if (!hasDialogBeenDisplayed(dialog3, form)) {
131 form.getDialogManager().addDialog(dialog3, form.getMethodToCall());
132 return getUIFModelAndView(form, "DialogView-Page1");
133 };
134
135
136 if (!hasDialogBeenAnswered(dialog3,form)){
137 return showDialog(dialog3, form, request, response);
138 }
139 doRestart = getBooleanDialogResponse(dialog3, form, request, response);
140
141
142 if (doRestart){
143 form.getDialogManager().removeAllDialogs();
144 form.setField1("Ok, let's start over.");
145 return getUIFModelAndView(form, "DialogView-Page1");
146 }
147
148
149 return getUIFModelAndView(form, "DialogView-Page2");
150 }
151
152
153
154
155
156
157
158
159
160
161 @RequestMapping(params = "methodToCall=goBack")
162 public ModelAndView goBack(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
163 HttpServletRequest request, HttpServletResponse response) {
164
165
166 form.getDialogManager().removeAllDialogs();
167 form.setField1("Ok, let's start over.");
168 return getUIFModelAndView(form, "DialogView-Page1");
169 }
170
171
172
173
174
175
176
177
178
179
180
181 @RequestMapping(params = "methodToCall=" + "doRadioDialogExample")
182 public ModelAndView doSomething(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
183 HttpServletRequest request, HttpServletResponse response) throws Exception {
184 String dialog1 = "sampleRadioButtonDialog";
185 if (!hasDialogBeenAnswered(dialog1, form)){
186
187 return showDialog(dialog1, form, request, response);
188 }
189
190 String choice = form.getDialogManager().getDialogExplanation(dialog1);
191 if (choice == null){
192 form.setField1("You didn't select one of the radio buttons");
193 } else {
194 form.setField1("You chose Radio Option "+choice);
195 }
196
197
198 form.getDialogManager().removeDialog(dialog1);
199
200 return getUIFModelAndView(form, "DialogView-Page1");
201 }
202
203
204
205
206
207
208
209
210
211
212
213 @RequestMapping(params = "methodToCall=" + "doOkCancelExample")
214 public ModelAndView doOKCancelExample(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
215 HttpServletRequest request, HttpServletResponse response) throws Exception {
216 String dialog1 = "preDefinedDialogOkCancel";
217 if (!hasDialogBeenAnswered(dialog1, form)){
218
219 return showDialog(dialog1, form, request, response);
220 }
221
222 boolean choice = getBooleanDialogResponse(dialog1, form, request, response);
223 StringBuilder sb = new StringBuilder("You selected ");
224 sb.append((choice)?"OK":"Cancel");
225 form.setField1(sb.toString());
226
227
228 form.getDialogManager().removeDialog(dialog1);
229
230 return getUIFModelAndView(form, "DialogView-Page1");
231 }
232
233
234
235
236
237
238
239
240
241
242
243 @RequestMapping(params = "methodToCall=" + "doRegularGroupAsDialog")
244 public ModelAndView doRegularGroupAsDialog(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
245 HttpServletRequest request, HttpServletResponse response) throws Exception {
246 String dialog1 = "myRegularGroup";
247 if (!hasDialogBeenAnswered(dialog1, form)){
248
249 return showDialog(dialog1, form, request, response);
250 }
251
252 boolean choice = getBooleanDialogResponse(dialog1, form, request, response);
253 StringBuilder sb = new StringBuilder("You selected ");
254 sb.append((choice)?"Yes":"No");
255 form.setField1(sb.toString());
256
257
258 form.getDialogManager().removeDialog(dialog1);
259
260 return getUIFModelAndView(form, "DialogView-Page1");
261 }
262
263
264
265
266
267
268
269
270
271
272
273
274 @RequestMapping(params = "methodToCall=" + "doExtendedDialog")
275 public ModelAndView doExtendedDialog(@ModelAttribute("KualiForm") UifDialogTestForm form, BindingResult result,
276 HttpServletRequest request, HttpServletResponse response) throws Exception {
277 String dialog1 = "extendedDialogGroup";
278 if (!hasDialogBeenAnswered(dialog1, form)){
279
280 return showDialog(dialog1, form, request, response);
281 }
282
283 boolean choice = getBooleanDialogResponse(dialog1, form, request, response);
284 StringBuilder sb = new StringBuilder("You selected ");
285 sb.append((choice)?"Yes":"No");
286 form.setField1(sb.toString());
287
288
289 form.getDialogManager().removeDialog(dialog1);
290
291 return getUIFModelAndView(form, "DialogView-Page1");
292 }
293 }