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