001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.demo.uif.controller;
017
018import org.kuali.rice.krad.demo.uif.form.KradSampleAppForm;
019import org.kuali.rice.krad.demo.uif.form.ServerPagingTestForm;
020import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
021import org.kuali.rice.krad.uif.view.ViewTheme;
022import org.kuali.rice.krad.web.controller.UifControllerBase;
023import org.kuali.rice.krad.web.form.UifFormBase;
024import org.springframework.stereotype.Controller;
025import org.springframework.validation.BindingResult;
026import org.springframework.web.bind.annotation.ModelAttribute;
027import org.springframework.web.bind.annotation.RequestMapping;
028import org.springframework.web.bind.annotation.RequestMethod;
029import org.springframework.web.servlet.ModelAndView;
030
031import javax.servlet.http.HttpServletRequest;
032import javax.servlet.http.HttpServletResponse;
033
034/**
035 * Controller for the server paging component library page
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039@Controller
040@RequestMapping(value = "/serverpaging")
041public class ServerPagingTestController extends UifControllerBase {
042
043    @Override
044    protected ServerPagingTestForm createInitialForm() {
045        ServerPagingTestForm form = new ServerPagingTestForm();
046        form.setViewId("Demo-CollectionServerPaging-View");
047
048        return form;
049    }
050
051    @Override
052    @RequestMapping(params = "methodToCall=start")
053    public ModelAndView start(UifFormBase form) {
054        return super.start(form);
055    }
056
057    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=changeTheme")
058    public ModelAndView changeTheme(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
059            HttpServletRequest request, HttpServletResponse response) {
060        changeTheme(form);
061
062        return getModelAndView(form);
063    }
064
065    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=validateView")
066    public ModelAndView validateView(@ModelAttribute("KualiForm") UifFormBase uiTestForm, BindingResult result,
067            HttpServletRequest request, HttpServletResponse response) {
068        KRADServiceLocatorWeb.getViewValidationService().validateView(uiTestForm);
069
070        return getModelAndView(uiTestForm);
071    }
072
073    private void changeTheme(UifFormBase form) {
074        String theme = ((KradSampleAppForm) form).getThemeName();
075        if (theme != null) {
076            ViewTheme newTheme = (ViewTheme) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryBean(
077                    theme));
078
079            if (newTheme != null) {
080                form.getView().setTheme(newTheme);
081            }
082        }
083    }
084}