View Javadoc

1   /**
2    * Copyright 2005-2014 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.demo.uif.form.ServerPagingTestForm;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.uif.view.ViewTheme;
22  import org.kuali.rice.krad.web.controller.UifControllerBase;
23  import org.kuali.rice.krad.web.form.UifFormBase;
24  import org.springframework.stereotype.Controller;
25  import org.springframework.validation.BindingResult;
26  import org.springframework.web.bind.annotation.ModelAttribute;
27  import org.springframework.web.bind.annotation.RequestMapping;
28  import org.springframework.web.bind.annotation.RequestMethod;
29  import org.springframework.web.servlet.ModelAndView;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  
34  /**
35   * Controller for the server paging component library page
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  @Controller
40  @RequestMapping(value = "/serverpaging")
41  public class ServerPagingTestController extends UifControllerBase {
42  
43      @Override
44      protected ServerPagingTestForm createInitialForm(HttpServletRequest request) {
45          ServerPagingTestForm form = new ServerPagingTestForm();
46          form.setViewId("Demo-CollectionServerPaging-View");
47  
48          return form;
49      }
50  
51      @Override
52      @RequestMapping(params = "methodToCall=start")
53      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
54              HttpServletRequest request, HttpServletResponse response) {
55          return super.start(form, result, request, response);
56      }
57  
58      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=changeTheme")
59      public ModelAndView changeTheme(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
60              HttpServletRequest request, HttpServletResponse response) {
61          changeTheme(form);
62  
63          return getUIFModelAndView(form);
64      }
65  
66      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=validateView")
67      public ModelAndView validateView(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
68              HttpServletRequest request, HttpServletResponse response) {
69          KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
70  
71          return getUIFModelAndView(uiTestForm);
72      }
73  
74      private void changeTheme(UifFormBase form) {
75          String theme = ((KradSampleAppForm) form).getThemeName();
76          if (theme != null) {
77              ViewTheme newTheme = (ViewTheme) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryObject(
78                      theme));
79  
80              if (newTheme != null) {
81                  form.getPostedView().setTheme(newTheme);
82                  form.getView().setTheme(newTheme);
83              }
84          }
85      }
86  }