View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.demo.kitchensink;
17  
18  import javax.management.RuntimeErrorException;
19  import javax.servlet.http.HttpServletRequest;
20  import javax.servlet.http.HttpServletResponse;
21  
22  import org.kuali.rice.krad.datadictionary.validation.ViewAttributeValueReader;
23  import org.kuali.rice.krad.service.DictionaryValidationService;
24  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25  import org.kuali.rice.krad.uif.UifParameters;
26  import org.kuali.rice.krad.uif.component.Component;
27  import org.kuali.rice.krad.uif.container.CollectionGroup;
28  import org.kuali.rice.krad.uif.container.Container;
29  import org.kuali.rice.krad.uif.container.Group;
30  import org.kuali.rice.krad.uif.field.DataField;
31  import org.kuali.rice.krad.uif.field.FieldGroup;
32  import org.kuali.rice.krad.uif.field.InputField;
33  import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
34  import org.kuali.rice.krad.uif.layout.TableLayoutManager;
35  import org.kuali.rice.krad.util.GlobalVariables;
36  import org.kuali.rice.krad.web.controller.UifControllerBase;
37  import org.kuali.rice.krad.web.form.UifFormBase;
38  import org.springframework.stereotype.Controller;
39  import org.springframework.validation.BindingResult;
40  import org.springframework.web.bind.annotation.ModelAttribute;
41  import org.springframework.web.bind.annotation.RequestMapping;
42  import org.springframework.web.bind.annotation.RequestMethod;
43  import org.springframework.web.servlet.ModelAndView;
44  
45  import java.beans.PropertyEditor;
46  import java.util.Enumeration;
47  import java.util.List;
48  import java.util.Map;
49  import java.util.Properties;
50  import java.util.Random;
51  
52  /**
53   * Controller for the Test UI Page
54   *
55   * @author Kuali Rice Team (rice.collab@kuali.org)
56   */
57  @Controller
58  @RequestMapping(value = "/uicomponents")
59  public class UifComponentsTestController extends UifControllerBase {
60  
61      /**
62       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
63       */
64      @Override
65      protected UifComponentsTestForm createInitialForm(HttpServletRequest request) {
66          return new UifComponentsTestForm();
67      }
68  
69      @Override
70      @RequestMapping(params = "methodToCall=start")
71      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
72              HttpServletRequest request, HttpServletResponse response) {
73          UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
74          form.setState("state1");
75          //for generated view:
76          if(form.getView().getId().equals("UifGeneratedFields")){
77              for(int i=0; i<100; i++){
78                  ((UifComponentsTestForm)form).getList1generated().add(
79                          new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
80              }
81              for(int i=0; i<100; i++){
82                  ((UifComponentsTestForm)form).getList2generated().add(
83                          new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
84              }
85              for(int i=0; i<10; i++){
86                  ((UifComponentsTestForm)form).getList3generated().add(
87                          new UITestObject("A" + i, "B" + i, "C" + i, "D" + i));
88                  for(int j=0; j<10; j++){
89                      ((UifComponentsTestForm)form).getList3generated().get(i).getSubList().add(
90                              new UITestObject("i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j, "i" + i + "-" + j));
91                  }
92              }
93          }
94  
95          GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome");
96  
97          return super.start(uiTestForm, result, request, response);
98      }
99  
100     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
101     public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
102             HttpServletRequest request, HttpServletResponse response) {
103         KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
104         return getUIFModelAndView(uiTestForm);
105     }
106 
107 
108     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
109     public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
110             HttpServletRequest request, HttpServletResponse response) {
111 
112         return getUIFModelAndView(uiTestForm, "UifCompView-Page1");
113     }
114 
115     /**
116      * Handles menu navigation between view pages
117      */
118     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
119     public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
120             HttpServletRequest request, HttpServletResponse response) {
121         String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
122 
123         if (pageId.equals("UifCompView-Page8")) {
124             GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
125             GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
126             GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
127             GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
128             GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
129             GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
130             GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
131             GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
132         }
133         // only refreshing page
134         form.setRenderFullView(false);
135 
136         return getUIFModelAndView(form, pageId);
137     }
138 
139     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
140     public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
141             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
142 
143         return getUIFModelAndView(uiTestForm);
144     }
145 
146     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
147     public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
148             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
149         GlobalVariables.getMessageMap().putError("field45", "serverTestError");
150         GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
151         GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
152 
153         return getUIFModelAndView(uiTestForm);
154     }
155 
156     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
157     public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
158             BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
159         GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
160         GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
161         GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
162 
163         GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
164         GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
165         GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
166 
167         GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
168         GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
169         GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
170         return refresh(uiTestForm, result, request, response);
171     }
172 
173     
174     /**
175      * Adds errors to fields defined in the validationMessageFields array
176      */
177     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
178     public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
179             HttpServletRequest request, HttpServletResponse response) {
180 
181         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
182             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
183             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
184         }
185         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
186             GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
187         }
188         
189         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
190         for(String key: propertyEditors.keySet()){
191             GlobalVariables.getMessageMap().putError(key, "error1Test");
192         }
193        
194         return getUIFModelAndView(form);
195     }
196     
197     /**
198      * Adds warnings to fields defined in the validationMessageFields array
199      */
200     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
201     public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
202             HttpServletRequest request, HttpServletResponse response) {
203 
204         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
205             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
206             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
207         }
208         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
209             GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
210         }
211 
212         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
213         for(String key: propertyEditors.keySet()){
214             GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
215         }
216 
217         return getUIFModelAndView(form);
218     }
219     
220     /**
221      * Adds infos to fields defined in the validationMessageFields array
222      */
223     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
224     public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
225             HttpServletRequest request, HttpServletResponse response) {
226 
227         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
228             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
229             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
230         }
231         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
232             GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
233         }
234 
235         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
236         for(String key: propertyEditors.keySet()){
237             GlobalVariables.getMessageMap().putInfo(key, "info1Test");
238         }
239 
240         return getUIFModelAndView(form);
241     }
242     
243     /**
244      * Adds all message types to fields defined in the validationMessageFields array
245      */
246     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
247     public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
248             HttpServletRequest request, HttpServletResponse response) {
249 
250         this.addErrors(form, result, request, response);
251         this.addWarnings(form, result, request, response);
252         this.addInfo(form, result, request, response);
253 
254         return getUIFModelAndView(form);
255     }
256 
257     /**
258      * Adds error and warning messages to fields defined in the validationMessageFields array
259      */
260     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
261     public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
262             HttpServletRequest request, HttpServletResponse response) {
263 
264         this.addErrors(form, result, request, response);
265         this.addWarnings(form, result, request, response);
266 
267         return getUIFModelAndView(form);
268     }
269 
270     /**
271      * Adds error and info messages to fields defined in the validationMessageFields array
272      */
273     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
274     public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
275             HttpServletRequest request, HttpServletResponse response) {
276 
277         this.addErrors(form, result, request, response);
278         this.addInfo(form, result, request, response);
279 
280         return getUIFModelAndView(form);
281     }
282 
283     /**
284      * Adds warning and info messages to fields defined in the validationMessageFields array
285      */
286     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarningInfoMessages")
287     public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
288             HttpServletRequest request, HttpServletResponse response) {
289 
290         this.addWarnings(form, result, request, response);
291         this.addInfo(form, result, request, response);
292 
293         return getUIFModelAndView(form);
294     }
295     
296     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState2")
297     public ModelAndView gotoState2(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
298             HttpServletRequest request, HttpServletResponse response) {
299         
300         KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state2");
301         if(!GlobalVariables.getMessageMap().hasErrors()){
302             form.setState("state2");
303         }
304 
305         return getUIFModelAndView(form);
306     }
307 
308     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState3")
309     public ModelAndView gotoState3(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
310             HttpServletRequest request, HttpServletResponse response) {
311 
312         KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state3");
313         if(!GlobalVariables.getMessageMap().hasErrors()){
314             form.setState("state3");
315         }
316 
317         return getUIFModelAndView(form);
318     }
319 
320     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=gotoState4")
321     public ModelAndView gotoState4(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
322             HttpServletRequest request, HttpServletResponse response) {
323 
324         KRADServiceLocatorWeb.getViewValidationService().validateView(form.getPostedView(), form, "state4");
325         if(!GlobalVariables.getMessageMap().hasErrors()){
326             form.setState("state4");
327         }
328         
329         return getUIFModelAndView(form);
330     }
331 
332 
333 
334     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=successCheck")
335     public ModelAndView successCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
336             HttpServletRequest request, HttpServletResponse response) {
337 
338         return getUIFModelAndView(form);
339     }
340 
341 
342     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=errorCheck")
343     public ModelAndView errorCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
344             HttpServletRequest request, HttpServletResponse response) {
345 
346         if(true) {
347             throw new RuntimeException("Generate fake incident report");
348         }
349 
350         return getUIFModelAndView(form);
351     }
352 
353     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=redirectCheck")
354     public ModelAndView redirectCheck(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
355             HttpServletRequest request, HttpServletResponse response) {
356         Properties props = new Properties();
357         props.put(UifParameters.VIEW_ID, form.getViewId());
358         props.put(UifParameters.FORM_KEY, form.getFormKey());
359         return performRedirect(form, "http://localhost:8080/kr-dev", props);
360     }
361 
362 
363 }