View Javadoc

1   /**
2    * Copyright 2005-2013 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 org.kuali.rice.krad.demo.uif.controller;
17  
18  import org.kuali.rice.krad.demo.uif.form.KradSampleAppForm;
19  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
20  import org.kuali.rice.krad.uif.util.ComponentFactory;
21  import org.kuali.rice.krad.uif.view.ViewTheme;
22  import org.kuali.rice.krad.util.GlobalVariables;
23  import org.kuali.rice.krad.web.controller.UifControllerBase;
24  import org.kuali.rice.krad.web.form.UifFormBase;
25  import org.springframework.stereotype.Controller;
26  import org.springframework.validation.BindingResult;
27  import org.springframework.web.bind.annotation.ModelAttribute;
28  import org.springframework.web.bind.annotation.RequestMapping;
29  import org.springframework.web.bind.annotation.RequestMethod;
30  import org.springframework.web.servlet.ModelAndView;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  /**
36   * Basic controller for the KRAD sample application
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @Controller
41  @RequestMapping(value = "/kradsampleapp")
42  public class KradSampleAppController extends UifControllerBase {
43  
44      @Override
45      protected KradSampleAppForm createInitialForm(HttpServletRequest request) {
46          return new KradSampleAppForm();
47      }
48  
49      @Override
50      @RequestMapping(params = "methodToCall=start")
51      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
52              HttpServletRequest request, HttpServletResponse response) {
53          //TODO tbd
54          return super.start(form, result, request, response);
55      }
56  
57      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=changeTheme")
58      public ModelAndView changeTheme(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
59              HttpServletRequest request, HttpServletResponse response) {
60          changeTheme(form);
61          return getUIFModelAndView(form);
62      }
63  
64      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=validateView")
65      public ModelAndView validateView(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
66              HttpServletRequest request, HttpServletResponse response) {
67          KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
68          return getUIFModelAndView(uiTestForm);
69      }
70  
71      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addGrowl")
72      public ModelAndView addGrowl(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
73              HttpServletRequest request, HttpServletResponse response) {
74          String extraInfo = (String)request.getParameter("extraInfo");
75          if(extraInfo == null){
76              extraInfo = "none";
77          }
78          GlobalVariables.getMessageMap().addGrowlMessage("Growl Message", "demo.fakeGrowl", extraInfo);
79          return getUIFModelAndView(uiTestForm);
80      }
81  
82      private void changeTheme(UifFormBase form) {
83          String theme = ((KradSampleAppForm) form).getThemeName();
84          if (theme != null) {
85              ViewTheme newTheme = (ViewTheme) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryObject(
86                      theme));
87              if (newTheme != null) {
88                  form.getPostedView().setTheme(newTheme);
89                  form.getView().setTheme(newTheme);
90              }
91          }
92      }
93  }