1 | package edu.iu.uis.sit.portal.portlet.admin.web; |
2 | |
3 | import javax.portlet.PortletRequest; |
4 | |
5 | import org.springframework.web.portlet.ModelAndView; |
6 | import org.springframework.web.portlet.mvc.SimpleFormController; |
7 | |
8 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletApplication; |
9 | import edu.iu.uis.sit.portal.portlet.admin.domain.PortletConfig; |
10 | import edu.iu.uis.sit.portal.portlet.admin.services.AdminService; |
11 | |
12 | public class PortletConfigController extends SimpleFormController { |
13 | private AdminService adminService; |
14 | |
15 | protected void onSubmitAction(Object command) throws Exception { |
16 | WebPortletConfig webPortletConfig = (WebPortletConfig) command; |
17 | getAdminService().savePortletConfig(webPortletConfig.getPortletApplication(), webPortletConfig.getPortletConfig()); |
18 | } |
19 | |
20 | protected ModelAndView onSubmitRender(Object command) throws Exception { |
21 | ModelAndView modelAndView = new ModelAndView("displayPortletConfigs"); |
22 | WebPortletConfig webPortletConfig = (WebPortletConfig) command; |
23 | modelAndView.addObject("portletApplicationId", webPortletConfig.getPortletApplication().getPortletApplicationId()); |
24 | modelAndView.addObject("portletConfigs", getAdminService().findPortletApplicationById(webPortletConfig.getPortletApplication().getPortletApplicationId()).getPortletConfigs()); |
25 | return modelAndView; |
26 | } |
27 | |
28 | protected Object formBackingObject(PortletRequest request) throws Exception { |
29 | WebPortletConfig webPortletConfig = new WebPortletConfig(); |
30 | if (request.getParameter("portletConfigId") != null) { |
31 | PortletConfig portletConfig = getAdminService().findPortletConfigById(Long.parseLong(request.getParameter("portletConfigId"))); |
32 | webPortletConfig.setPortletApplication(portletConfig.getPortletApplication()); |
33 | webPortletConfig.setPortletConfig(portletConfig); |
34 | } else { |
35 | PortletApplication portletApplication = getAdminService().findPortletApplicationById(Long.parseLong(request.getParameter("portletApplicationId"))); |
36 | webPortletConfig.setPortletApplication(portletApplication); |
37 | } |
38 | |
39 | return webPortletConfig; |
40 | } |
41 | |
42 | public AdminService getAdminService() { |
43 | return adminService; |
44 | } |
45 | |
46 | public void setAdminService(AdminService adminService) { |
47 | this.adminService = adminService; |
48 | } |
49 | } |