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.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.kuali.rice.krad.datadictionary.validation.ViewAttributeValueReader;
22  import org.kuali.rice.krad.service.DictionaryValidationService;
23  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
24  import org.kuali.rice.krad.uif.UifParameters;
25  import org.kuali.rice.krad.uif.component.Component;
26  import org.kuali.rice.krad.uif.container.CollectionGroup;
27  import org.kuali.rice.krad.uif.container.Container;
28  import org.kuali.rice.krad.uif.container.Group;
29  import org.kuali.rice.krad.uif.field.DataField;
30  import org.kuali.rice.krad.uif.field.FieldGroup;
31  import org.kuali.rice.krad.uif.field.InputField;
32  import org.kuali.rice.krad.uif.layout.StackedLayoutManager;
33  import org.kuali.rice.krad.uif.layout.TableLayoutManager;
34  import org.kuali.rice.krad.util.GlobalVariables;
35  import org.kuali.rice.krad.web.controller.UifControllerBase;
36  import org.kuali.rice.krad.web.form.UifFormBase;
37  import org.springframework.stereotype.Controller;
38  import org.springframework.validation.BindingResult;
39  import org.springframework.web.bind.annotation.ModelAttribute;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.bind.annotation.RequestMethod;
42  import org.springframework.web.servlet.ModelAndView;
43  
44  import java.beans.PropertyEditor;
45  import java.util.Enumeration;
46  import java.util.List;
47  import java.util.Map;
48  import java.util.Random;
49  
50  /**
51   * Controller for the Test UI Page
52   *
53   * @author Kuali Rice Team (rice.collab@kuali.org)
54   */
55  @Controller
56  @RequestMapping(value = "/uicomponents")
57  public class UifComponentsTestController extends UifControllerBase {
58  
59      /**
60       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
61       */
62      @Override
63      protected UifComponentsTestForm createInitialForm(HttpServletRequest request) {
64          return new UifComponentsTestForm();
65      }
66  
67      @Override
68      @RequestMapping(params = "methodToCall=start")
69      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
70              HttpServletRequest request, HttpServletResponse response) {
71          UifComponentsTestForm uiTestForm = (UifComponentsTestForm) form;
72  
73          GlobalVariables.getMessageMap().addGrowlMessage("Welcome!", "kitchenSink.welcome");
74  
75          return super.start(uiTestForm, result, request, response);
76      }
77  
78      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
79      public ModelAndView save(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
80              HttpServletRequest request, HttpServletResponse response) {
81          KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
82          return getUIFModelAndView(uiTestForm);
83      }
84  
85  
86      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=close")
87      public ModelAndView close(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm, BindingResult result,
88              HttpServletRequest request, HttpServletResponse response) {
89  
90          return getUIFModelAndView(uiTestForm, "UifCompView-Page1");
91      }
92  
93      /**
94       * Handles menu navigation between view pages
95       */
96      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
97      public ModelAndView navigate(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
98              HttpServletRequest request, HttpServletResponse response) {
99          String pageId = form.getActionParamaterValue(UifParameters.NAVIGATE_TO_PAGE_ID);
100 
101         if (pageId.equals("UifCompView-Page8")) {
102             GlobalVariables.getMessageMap().putError("gField1", "serverTestError");
103             GlobalVariables.getMessageMap().putError("gField1", "serverTestError2");
104             GlobalVariables.getMessageMap().putError("gField2", "serverTestError");
105             GlobalVariables.getMessageMap().putError("gField3", "serverTestError");
106             GlobalVariables.getMessageMap().putWarning("gField1", "serverTestWarning");
107             GlobalVariables.getMessageMap().putWarning("gField2", "serverTestWarning");
108             GlobalVariables.getMessageMap().putInfo("gField2", "serverTestInfo");
109             GlobalVariables.getMessageMap().putInfo("gField3", "serverTestInfo");
110         }
111         // only refreshing page
112         form.setRenderFullView(false);
113 
114         return getUIFModelAndView(form, pageId);
115     }
116 
117     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshProgGroup")
118     public ModelAndView refreshProgGroup(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
119             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
120 
121         return getUIFModelAndView(uiTestForm);
122     }
123 
124     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=refreshWithServerMessages")
125     public ModelAndView refreshWithServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
126             BindingResult result, HttpServletRequest request, HttpServletResponse response) {
127         GlobalVariables.getMessageMap().putError("field45", "serverTestError");
128         GlobalVariables.getMessageMap().putWarning("field45", "serverTestWarning");
129         GlobalVariables.getMessageMap().putInfo("field45", "serverTestInfo");
130 
131         return getUIFModelAndView(uiTestForm);
132     }
133 
134     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=genCollectionServerMessages")
135     public ModelAndView genCollectionServerMessages(@ModelAttribute("KualiForm") UifComponentsTestForm uiTestForm,
136             BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
137         GlobalVariables.getMessageMap().putError("list2[0].field1", "serverTestError");
138         GlobalVariables.getMessageMap().putWarning("list2[0].field1", "serverTestWarning");
139         GlobalVariables.getMessageMap().putInfo("list2[0].field1", "serverTestInfo");
140 
141         GlobalVariables.getMessageMap().putError("list3[0].field1", "serverTestError");
142         GlobalVariables.getMessageMap().putWarning("list3[0].field1", "serverTestWarning");
143         GlobalVariables.getMessageMap().putInfo("list3[0].field1", "serverTestInfo");
144 
145         GlobalVariables.getMessageMap().putError("list5[0].subList[0].field1", "serverTestError");
146         GlobalVariables.getMessageMap().putWarning("list5[0].subList[0].field1", "serverTestWarning");
147         GlobalVariables.getMessageMap().putInfo("list5[0].subList[0].field1", "serverTestInfo");
148         return refresh(uiTestForm, result, request, response);
149     }
150 
151     
152     /**
153      * Adds errors to fields defined in the validationMessageFields array
154      */
155     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrors")
156     public ModelAndView addErrors(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
157             HttpServletRequest request, HttpServletResponse response) {
158 
159         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
160             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section1", "errorSectionTest");
161             GlobalVariables.getMessageMap().putError("Demo-ValidationLayout-Section2", "errorSectionTest");
162         }
163         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
164             GlobalVariables.getMessageMap().putError("badKey", "unmatchedTest");
165         }
166         
167         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
168         for(String key: propertyEditors.keySet()){
169             GlobalVariables.getMessageMap().putError(key, "error1Test");
170         }
171        
172         return getUIFModelAndView(form);
173     }
174     
175     /**
176      * Adds warnings to fields defined in the validationMessageFields array
177      */
178     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarnings")
179     public ModelAndView addWarnings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
180             HttpServletRequest request, HttpServletResponse response) {
181 
182         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
183             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section1", "warningSectionTest");
184             GlobalVariables.getMessageMap().putWarning("Demo-ValidationLayout-Section2", "warningSectionTest");
185         }
186         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
187             GlobalVariables.getMessageMap().putWarning("badKey", "unmatchedTest");
188         }
189 
190         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
191         for(String key: propertyEditors.keySet()){
192             GlobalVariables.getMessageMap().putWarning(key, "warning1Test");
193         }
194 
195         return getUIFModelAndView(form);
196     }
197     
198     /**
199      * Adds infos to fields defined in the validationMessageFields array
200      */
201     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addInfo")
202     public ModelAndView addInfo(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
203             HttpServletRequest request, HttpServletResponse response) {
204 
205         if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageSectionMessages")){
206             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section1", "infoSectionTest");
207             GlobalVariables.getMessageMap().putInfo("Demo-ValidationLayout-Section2", "infoSectionTest");
208         }
209         else if(form.getPostedView().getCurrentPageId().equals("Demo-ValidationLayout-SectionsPageUnmatched")){
210             GlobalVariables.getMessageMap().putInfo("badKey", "unmatchedTest");
211         }
212 
213         Map<String, PropertyEditor> propertyEditors = form.getPostedView().getViewIndex().getFieldPropertyEditors();
214         for(String key: propertyEditors.keySet()){
215             GlobalVariables.getMessageMap().putInfo(key, "info1Test");
216         }
217 
218         return getUIFModelAndView(form);
219     }
220     
221     /**
222      * Adds all message types to fields defined in the validationMessageFields array
223      */
224     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAllMessages")
225     public ModelAndView addAllMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
226             HttpServletRequest request, HttpServletResponse response) {
227 
228         this.addErrors(form, result, request, response);
229         this.addWarnings(form, result, request, response);
230         this.addInfo(form, result, request, response);
231 
232         return getUIFModelAndView(form);
233     }
234 
235     /**
236      * Adds error and warning messages to fields defined in the validationMessageFields array
237      */
238     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorWarnMessages")
239     public ModelAndView addErrorWarnMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
240             HttpServletRequest request, HttpServletResponse response) {
241 
242         this.addErrors(form, result, request, response);
243         this.addWarnings(form, result, request, response);
244 
245         return getUIFModelAndView(form);
246     }
247 
248     /**
249      * Adds error and info messages to fields defined in the validationMessageFields array
250      */
251     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addErrorInfoMessages")
252     public ModelAndView addErrorInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
253             HttpServletRequest request, HttpServletResponse response) {
254 
255         this.addErrors(form, result, request, response);
256         this.addInfo(form, result, request, response);
257 
258         return getUIFModelAndView(form);
259     }
260 
261     /**
262      * Adds warning and info messages to fields defined in the validationMessageFields array
263      */
264     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addWarningInfoMessages")
265     public ModelAndView addWarnInfoMessages(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
266             HttpServletRequest request, HttpServletResponse response) {
267 
268         this.addWarnings(form, result, request, response);
269         this.addInfo(form, result, request, response);
270 
271         return getUIFModelAndView(form);
272     }
273 
274 }