类 AbstractController

  • 所有已实现的接口:
    Aware, ApplicationContextAware, PortletContextAware, Controller
    直接已知子类:
    ParameterizableViewController, PortletWrappingController

    public abstract class AbstractController
    extends PortletContentGenerator
    implements Controller
    Convenient superclass for controller implementations, using the Template Method design pattern.

    As stated in the Controller interface, a lot of functionality is already provided by certain abstract base controllers. The AbstractController is one of the most important abstract base controller providing basic features such controlling if a session is required and render caching.

    Workflow (and that defined by interface):

    1. If this is an action request, handleActionRequest will be called by the DispatcherPortlet once to perform the action defined by this controller.
    2. If a session is required, try to get it (PortletException if not found).
    3. Call method handleActionRequestInternal, (optionally synchronizing around the call on the PortletSession), which should be overridden by extending classes to provide actual functionality to perform the desired action of the controller. This will be executed only once.
    4. For a straight render request, or the render phase of an action request (assuming the same controller is called for the render phase -- see tip below), handleRenderRequest will be called by the DispatcherPortlet repeatedly to render the display defined by this controller.
    5. If a session is required, try to get it (PortletException if none found).
    6. It will control caching as defined by the cacheSeconds property.
    7. Call method handleRenderRequestInternal, (optionally synchronizing around the call on the PortletSession), which should be overridden by extending classes to provide actual functionality to return ModelAndView objects. This will be executed repeatedly as the portal updates the current displayed page.

    Exposed configuration properties (and those defined by interface):

    namedefaultdescription
    requireSessionfalsewhether a session should be required for requests to be able to be handled by this controller. This ensures, derived controller can - without fear of Nullpointers - call request.getSession() to retrieve a session. If no session can be found while processing the request, a PortletException will be thrown
    synchronizeOnSessionfalsewhether the calls to handleRenderRequestInternal and handleRenderRequestInternal should be synchronized around the PortletSession, to serialize invocations from the same client. No effect if there is no PortletSession.
    cacheSeconds-1indicates the amount of seconds to specify caching is allowed in the render response generatedby this request. 0 (zero) will indicate no caching is allowed at all, -1 (the default) will not override the portlet configuration and any positive number will cause the render response to declare the amount indicated as seconds to cache the content
    renderWhenMinimizedfalsewhether should be rendered when the portlet is in a minimized state -- will return null for the ModelandView when the portlet is minimized and this is false

    TIP: The controller mapping will be run twice by the PortletDispatcher for action requests -- once for the action phase and again for the render phase. You can reach the render phase of a different controller by simply changing the values for the criteria your mapping is using, such as portlet mode or a request parameter, during the action phase of your controller. This is very handy since redirects within the portlet are apparently impossible. Before doing this, it is usually wise to call clearAllRenderParameters and then explicitly set all the parameters that you want the new controller to see. This avoids unexpected parameters from being passed to the render phase of the second controller, such as the parameter indicating a form submit ocurred in an AbstractFormController.

    Thanks to Rainer Schmitz and Nick Lothian for their suggestions!

    从以下版本开始:
    2.0
    作者:
    John A. Lewis, Juergen Hoeller
    另请参阅:
    ResourceAwareController, EventAwareController