001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache 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 * https://www.apache.org/licenses/LICENSE-2.0 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 */ 016 017package org.springframework.web.portlet.mvc; 018 019import javax.portlet.ActionRequest; 020import javax.portlet.ActionResponse; 021import javax.portlet.RenderRequest; 022import javax.portlet.RenderResponse; 023 024import org.springframework.web.portlet.ModelAndView; 025 026/** 027 * Base portlet Controller interface, representing a component that receives 028 * RenderRequest/RenderResponse and ActionRequest/ActionResponse like a 029 * {@code Portlet} but is able to participate in an MVC workflow. 030 * 031 * <p>Any implementation of the portlet Controller interface should be a 032 * <i>reusable, threadsafe</i> class, capable of handling multiple 033 * portlet requests throughout the lifecycle of an application. To be able to 034 * configure Controller(s) in an easy way, Controllers are usually JavaBeans.</p> 035 * 036 * <p><b><a name="workflow">Workflow</a>:</b></p> 037 * 038 * <p>After the DispatcherPortlet has received a request and has done its work 039 * to resolve locales, themes and suchlike, it tries to resolve a 040 * Controller to handle that request, using a 041 * {@link org.springframework.web.portlet.HandlerMapping HandlerMapping}. 042 * When a Controller has been found, the 043 * {@link #handleRenderRequest handleRenderRequest} or {@link #handleActionRequest handleActionRequest} 044 * method will be invoked, which is responsible for handling the actual 045 * request and - if applicable - returning an appropriate ModelAndView. 046 * So actually, these method are the main entrypoint for the 047 * {@link org.springframework.web.portlet.DispatcherPortlet DispatcherPortlet} 048 * which delegates requests to controllers.</p> 049 * 050 * <p>So basically any <i>direct</i> implementation of the Controller interface 051 * just handles RenderRequests/ActionRequests and should return a ModelAndView, to be 052 * further used by the DispatcherPortlet. Any additional functionality such as 053 * optional validation, form handling, etc should be obtained through extending 054 * one of the abstract controller classes mentioned above.</p> 055 * 056 * @author William G. Thompson, Jr. 057 * @author John A. Lewis 058 * @since 2.0 059 * @see ResourceAwareController 060 * @see EventAwareController 061 * @see SimpleControllerHandlerAdapter 062 * @see AbstractController 063 * @see org.springframework.web.portlet.context.PortletContextAware 064 */ 065public interface Controller { 066 067 /** 068 * Process the action request. There is nothing to return. 069 * @param request current portlet action request 070 * @param response current portlet action response 071 * @throws Exception in case of errors 072 */ 073 void handleActionRequest(ActionRequest request, ActionResponse response) throws Exception; 074 075 /** 076 * Process the render request and return a ModelAndView object which the DispatcherPortlet 077 * will render. A {@code null} return value is not an error: It indicates that this 078 * object completed request processing itself, thus there is no ModelAndView to render. 079 * @param request current portlet render request 080 * @param response current portlet render response 081 * @return a ModelAndView to render, or null if handled directly 082 * @throws Exception in case of errors 083 */ 084 ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) throws Exception; 085 086}