Spring 프레임 워 크 참고 문서 (5) - The Web 의 Portlet MVC Framework

225293 단어 spring
Spring 프레임 워 크 참고 문서 (5) - The Web 의 Portlet MVC Framework
Part V. The Web
이 부분 참고 문 서 는 소개 할 것 이다. spring 프레임 워 크 는 표현 층 에 대한 지원 (특히 웹 표현 층 에 대한 지원) 과 웹 socket 형식의 웹 응용 을 지원 합 니 다.
spring 프레임 워 크 는 자신의 웹 프레임 워 크 를 가지 고 있 습 니 다 - Spring Web MVC, 이 부분 은 앞의 두 장 에서 소개 된다.후속 장절 소개 spring 프레임 워 크 와 기타 웹 기술 의 통합, 예 를 들 어 JSF 기다리다
Spring MVC 프레임 워 크, portlet 프레임 워 크 를 소개 합 니 다.Following that is coverage of Spring Framework’s MVC portlet framework.
끝 부분 은 Spring 프레임 워 크 를 전면적으로 덮어 씁 니 다. Chapter 20, 웹 소켓 지원 (포함) Section 20.4, “STOMP Over WebSocket Messaging Architecture”)。
Chapter 16, 웹 MVC 프레임 워 크 Chapter 17, 보기 기술 Chapter 18, 다른 웹 프레임 워 크 와 통합 Chapter 19, Portlet MVC Framework
Chapter 20, WebSocket 지원 19. Portlet MVC Framework
19.1 Introduction
JSR-168 The Java Portlet Specification
For more general information about portlet development, please review a whitepaper from Oracle entitled "Introduction to JSR 168", and of course the JSR-168 Specification itself.
In addition to supporting conventional (servlet-based) Web development, Spring also supports JSR-168 Portlet development. As much as possible, the Portlet MVC framework is a mirror image of the Web MVC framework, and also uses the same underlying view abstractions and integration technology. So, be sure to review the chapters entitled Chapter 16, 웹 MVC 프레임 워 크 and Chapter 17, 보기 기술 before continuing with this chapter.
Bear in mind that while the concepts of Spring MVC are the same in Spring Portlet MVC, there are some notable differences created by the unique workflow of JSR-168 portlets.
The main way in which portlet workflow differs from servlet workflow is that the request to the portlet can have two distinct phases: the action phase and the render phase. The action phase is executed only once and is where any backend changes or actions occur, such as making changes in a database. The render phase then produces what is displayed to the user each time the display is refreshed. The critical point here is that for a single overall request, the action phase is executed only once, but the render phase may be executed multiple times. This provides (and requires) a clean separation between the activities that modify the persistent state of your system and the activities that generate what is displayed to the user.
Spring Web Flow
Spring Web Flow (SWF) aims to be the best solution for the management of web application page flow.
SWF integrates with existing frameworks like Spring MVC and JSF, in both Servlet and Portlet environments. If you have a business process (or processes) that would benefit from a conversational model as opposed to a purely request model, then SWF may be the solution.
SWF allows you to capture logical page flows as self-contained modules that are reusable in different situations, and as such is ideal for building web application modules that guide the user through controlled navigations that drive business processes.
For more information about SWF, consult the Spring Web Flow website.
The dual phases of portlet requests are one of the real strengths of the JSR-168 specification. For example, dynamic search results can be updated routinely on the display without the user explicitly rerunning the search. Most other portlet MVC frameworks attempt to completely hide the two phases from the developer and make it look as much like traditional servlet development as possible - we think this approach removes one of the main benefits of using portlets. So, the separation of the two phases is preserved throughout the Spring Portlet MVC framework. The primary manifestation of this approach is that where the servlet version of the MVC classes will have one method that deals with the request, the portlet version of the MVC classes will have two methods that deal with the request: one for the action phase and one for the render phase. For example, where the servlet version of AbstractController has the handleRequestInternal(..) method, the portlet version ofAbstractController has handleActionRequestInternal(..) and handleRenderRequestInternal(..) methods.
The framework is designed around a DispatcherPortlet that dispatches requests to handlers, with configurable handler mappings and view resolution, just as theDispatcherServlet in the web framework does. File upload is also supported in the same way.
Locale resolution and theme resolution are not supported in Portlet MVC - these areas are in the purview of the portal/portlet container and are not appropriate at the Spring level. However, all mechanisms in Spring that depend on the locale (such as internationalization of messages) will still function properly becauseDispatcherPortlet exposes the current locale in the same way as DispatcherServlet.
19.1.1 Controllers - MVC 의 C 층
기본 정적 처리 장 치 는 매우 간단 하 다. Controller 인터페이스, 두 가지 방법 만 제공 합 니 다.
void handleActionRequest(request,response)
ModelAndView handleRenderRequest(request,response)
이 프레임 워 크 의 실현 층 에는 비슷 한 컨트롤 러 가 많이 포함 되 어 있다. 예 를 들 어 AbstractController, SimpleFormController 잠깐 만.데이터 바 인 딩, 명령 대상 의 사용, 모델 처리 와 보기 해석 은 servlet 프레임 워 크 에서 모두 같 습 니 다.
19.1.2 Views - MVC 의 V 층
All the view rendering capabilities of the servlet framework are used directly via a special bridge servlet named ViewRendererServlet. By using this servlet, the portlet request is converted into a servlet request and the view can be rendered using the entire normal servlet infrastructure. This means all the existing renderers, such as JSP, Velocity, etc., can still be used within the portlet.
19.1.3 Web-scoped beans
Spring Portlet MVC supports beans whose lifecycle is scoped to the current HTTP request or HTTP Session (both normal and global). This is not a specific feature of Spring Portlet MVC itself, but rather of the WebApplicationContext container(s) that Spring Portlet MVC uses. These bean scopes are described in detail inSection 5.5.4, "요청 역할 영역, 세 션 역할 영역 과 전역 세 션 역할 영역"
19.2 The DispatcherPortlet
Portlet MVC is a request-driven web MVC framework, designed around a portlet that dispatches requests to controllers and offers other functionality facilitating the development of portlet applications. Spring’s DispatcherPortlet however, does more than just that. It is completely integrated with the Spring ApplicationContextand allows you to use every other feature Spring has.
Like ordinary portlets, the DispatcherPortlet is declared in the portlet.xml file of your web application:

    sample
    org.springframework.web.portlet.DispatcherPortlet
    
        text/html
        view
    
    
        </span>Sample Portlet<span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/>
<span class="hl-tag" style="color:rgb(63,127,127)"/></code></pre> 
       <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> now needs to be configured.</p> 
       <p style="margin-top:15px; margin-bottom:15px">In the Portlet MVC framework, each <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> has its own <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>, which inherits all the beans already defined in the Root<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>. These inherited beans can be overridden in the portlet-specific scope, and new scope-specific beans can be defined local to a given portlet instance.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The framework will, on initialization of a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>, look for a file named <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">[portlet-name]-portlet.xml</code> in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WEB-INF</code> directory of your web application and create the beans defined there (overriding the definitions of any beans defined with the same name in the global scope).</p> 
       <p style="margin-top:15px; margin-bottom:15px">The config location used by the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> can be modified through a portlet initialization parameter (see below for details).</p> 
       <p style="margin-top:15px; margin-bottom:15px">The Spring <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> has a few special beans it uses, in order to be able to process requests and render the appropriate views. These beans are included in the Spring framework and can be configured in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>, just as any other bean would be configured. Each of those beans is described in more detail below. Right now, we’ll just mention them, just to let you know they exist and to enable us to go on talking about the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>. For most of the beans, defaults are provided so you don’t have to worry about configuring them.</p> 
       <div class="table" style="margin:1em; padding:0.5em; text-align:center"> 
        <p class="title" style="margin-top:15px; margin-bottom:15px; margin-left:-1em; text-align:left; padding-left:1em"> <strong>Table 19.1. Special beans in the WebApplicationContext</strong></p> 
        <div class="table-contents" style="margin:0pt"> 
         <table summary="Special beans in the WebApplicationContext" style="border-spacing:0px; line-height:1.6; border-width:0.5pt; border-style:solid; border-color:initial; border-collapse:collapse; width:1150px"> 
          <colgroup> 
           <col class="col_1"/> 
           <col class="col_2"/> 
          </colgroup> 
          <thead style="background:rgb(245,245,245)"> 
           <tr style="border:none"> 
            <th align="left" valign="top" style="padding:6px 13px; border-right:0.5pt solid; border-bottom:0.5pt solid; border-top:none!important; border-left:none!important"> Expression</th> 
            <th align="left" valign="top" style="padding:6px 13px; border-bottom:0.5pt solid; border-top:none!important; border-right:none!important; border-left:none!important"> Explanation</th> 
           </tr> 
          </thead> 
          <tbody> 
           <tr style="border:none"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">handler mapping(s)</p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">(Section 19.5, “Handler mappings”) a list of pre- and post-processors and controllers that will be executed if they match certain criteria (for instance a matching portlet mode specified with the controller)</p> </td> 
           </tr> 
           <tr style="border:none; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">controller(s)</p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">(Section 19.4, “Controllers”) the beans providing the actual functionality (or at least, access to the functionality) as part of the MVC triad</p> </td> 
           </tr> 
           <tr style="border:none"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">view resolver</p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">(Section 19.6, “Views and resolving them”) capable of resolving view names to view definitions</p> </td> 
           </tr> 
           <tr style="border:none; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">multipart resolver</p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">(Section 19.7, “Multipart (file upload) support”) offers functionality to process file uploads from HTML forms</p> </td> 
           </tr> 
           <tr style="border:none"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:none!important; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">handler exception resolver</p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border:none!important"> <p style="margin-top:0px; margin-bottom:0px">(Section 19.8, “Handling exceptions”) offers functionality to map exceptions to views or implement other more complex exception handling code</p> </td> 
           </tr> 
          </tbody> 
         </table> 
        </div> 
       </div> 
       <br class="table-break"/> 
       <p style="margin-top:15px; margin-bottom:15px">When a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> is setup for use and a request comes in for that specific <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>, it starts processing the request. The list below describes the complete process a request goes through if handled by a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>:</p> 
       <div class="orderedlist" style="margin:0pt"> 
        <ol class="orderedlist" type="1" style="padding-left:30px"> 
         <li class="listitem">The locale returned by <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletRequest.getLocale()</code> is bound to the request to let elements in the process resolve the locale to use when processing the request (rendering the view, preparing data, etc.).</li> 
         <li class="listitem">If a multipart resolver is specified and this is an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code>, the request is inspected for multiparts and if they are found, it is wrapped in a<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">MultipartActionRequest</code> for further processing by other elements in the process. (See Section 19.7, “Multipart (file upload) support” for further information about multipart handling).</li> 
         <li class="listitem">An appropriate handler is searched for. If a handler is found, the execution chain associated with the handler (pre-processors, post-processors, controllers) will be executed in order to prepare a model.</li> 
         <li class="listitem">If a model is returned, the view is rendered, using the view resolver that has been configured with the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>. If no model is returned (which could be due to a pre- or post-processor intercepting the request, for example, for security reasons), no view is rendered, since the request could already have been fulfilled.</li> 
        </ol> 
       </div> 
       <p style="margin-top:15px; margin-bottom:15px">Exceptions that are thrown during processing of the request get picked up by any of the handler exception resolvers that are declared in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>. Using these exception resolvers you can define custom behavior in case such exceptions get thrown.</p> 
       <p style="margin-top:15px; margin-bottom:15px">You can customize Spring’s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> by adding context parameters in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">portlet.xml</code> file or portlet init-parameters. The possibilities are listed below.</p> 
       <div class="table" style="margin:1em; padding:0.5em; text-align:center"> 
        <p class="title" style="margin-top:15px; margin-bottom:15px; margin-left:-1em; text-align:left; padding-left:1em"> <strong>Table 19.2. DispatcherPortlet initialization parameters</strong></p> 
        <div class="table-contents" style="margin:0pt"> 
         <table summary="DispatcherPortlet initialization parameters" style="border-spacing:0px; line-height:1.6; border-width:0.5pt; border-style:solid; border-color:initial; border-collapse:collapse; width:1150px"> 
          <colgroup> 
           <col class="col_1"/> 
           <col class="col_2"/> 
          </colgroup> 
          <thead style="background:rgb(245,245,245)"> 
           <tr style="border:none"> 
            <th align="left" valign="top" style="padding:6px 13px; border-right:0.5pt solid; border-bottom:0.5pt solid; border-top:none!important; border-left:none!important"> Parameter</th> 
            <th align="left" valign="top" style="padding:6px 13px; border-bottom:0.5pt solid; border-top:none!important; border-right:none!important; border-left:none!important"> Explanation</th> 
           </tr> 
          </thead> 
          <tbody> 
           <tr style="border:none"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">contextClass</code></p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">Class that implements <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>, which will be used to instantiate the context used by this portlet. If this parameter isn’t specified, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">XmlPortletApplicationContext</code> will be used.</p> </td> 
           </tr> 
           <tr style="border:none; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">contextConfigLocation</code></p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">String which is passed to the context instance (specified by <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">contextClass</code>) to indicate where context(s) can be found. The String is potentially split up into multiple Strings (using a comma as a delimiter) to support multiple contexts (in case of multiple context locations, for beans that are defined twice, the latest takes precedence).</p> </td> 
           </tr> 
           <tr style="border:none"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">namespace</code></p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">The namespace of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code>. Defaults to <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">[portlet-name]-portlet</code>.</p> </td> 
           </tr> 
           <tr style="border:none; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:none!important; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">viewRendererUrl</code></p> </td> 
            <td align="left" valign="top" style="padding:6px 7px; border:none!important"> <p style="margin-top:0px; margin-bottom:0px">The URL at which <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> can access an instance of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code> (see Section 19.3, “The ViewRendererServlet”).</p> </td> 
           </tr> 
          </tbody> 
         </table> 
        </div> 
       </div> 
       <br class="table-break"/> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.3 The ViewRendererServlet</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">The rendering process in Portlet MVC is a bit more complex than in Web MVC. In order to reuse all the view technologies from Spring Web MVC, we must convert the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletRequest</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletResponse</code> to <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HttpServletRequest</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HttpServletResponse</code> and then call the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">render</code> method of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code>. To do this,<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> uses a special servlet that exists for just this purpose: the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code>.</p> 
       <p style="margin-top:15px; margin-bottom:15px">In order for <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> rendering to work, you must declare an instance of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code> in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">web.xml</code> file for your web application as follows:</p> 
       <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><servlet/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><servlet-name/></span>ViewRendererServlet<span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"><servlet-class/></span>org.springframework.web.servlet.ViewRendererServlet<span class="hl-tag" style="color:rgb(63,127,127)"/>
<span class="hl-tag" style="color:rgb(63,127,127)"/>

<span class="hl-tag" style="color:rgb(63,127,127)"><servlet-mapping/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><servlet-name/></span>ViewRendererServlet<span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"><url-pattern/></span>/WEB-INF/servlet/view<span class="hl-tag" style="color:rgb(63,127,127)"/>
<span class="hl-tag" style="color:rgb(63,127,127)"/></code></pre> 
       <p style="margin-top:15px; margin-bottom:15px">To perform the actual rendering, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> does the following:</p> 
       <div class="orderedlist" style="margin:0pt"> 
        <ol class="orderedlist" type="1" style="padding-left:30px"> 
         <li class="listitem">Binds the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebApplicationContext</code> to the request as an attribute under the same <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WEB_APPLICATION_CONTEXT_ATTRIBUTE</code> key that <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherServlet</code> uses.</li> 
         <li class="listitem">Binds the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Model</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code> objects to the request to make them available to the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code>.</li> 
         <li class="listitem">Constructs a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletRequestDispatcher</code> and performs an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">include</code> using the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">/WEB- INF/servlet/view</code> URL that is mapped to the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code>.</li> 
        </ol> 
       </div> 
       <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code> is then able to call the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">render</code> method on the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code> with the appropriate arguments.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The actual URL for the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code> can be changed using <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>'s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">viewRendererUrl</code> configuration parameter.</p> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.4 Controllers</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">The controllers in Portlet MVC are very similar to the Web MVC Controllers, and porting code from one to the other should be simple.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The basis for the Portlet MVC controller architecture is the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.portlet.mvc.Controller</code> interface, which is listed below.</p> 
       <pre><code liberation="" mono=""><span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">interface</span> Controller {

    <span class="hl-tag" style="color:blue">/**
     * Process the render request and return a ModelAndView object which the
     * DispatcherPortlet will render.
     */</span>
    ModelAndView handleRenderRequest(RenderRequest request,
            RenderResponse response) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception;

    <span class="hl-tag" style="color:blue">/**
     * Process the action request. There is nothing to return.
     */</span>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> handleActionRequest(ActionRequest request,
            ActionResponse response) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception;

}</code></pre> 
       <p style="margin-top:15px; margin-bottom:15px">As you can see, the Portlet <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> interface requires two methods that handle the two phases of a portlet request: the action request and the render request. The action phase should be capable of handling an action request, and the render phase should be capable of handling a render request and returning an appropriate model and view. While the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> interface is quite abstract, Spring Portlet MVC offers several controllers that already contain a lot of the functionality you might need; most of these are very similar to controllers from Spring Web MVC. The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> interface just defines the most common functionality required of every controller: handling an action request, handling a render request, and returning a model and a view.</p> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.4.1 AbstractController and PortletContentGenerator</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Of course, just a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> interface isn’t enough. To provide a basic infrastructure, all of Spring Portlet MVC’s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code>s inherit from <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractController</code>, a class offering access to Spring’s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ApplicationContext</code> and control over caching.</p> 
        <div class="table" style="margin:1em; padding:0.5em; text-align:center"> 
         <p class="title" style="margin-top:15px; margin-bottom:15px; margin-left:-1em; text-align:left; padding-left:1em"> <strong>Table 19.3. Features offered by the AbstractController</strong></p> 
         <div class="table-contents" style="margin:0pt"> 
          <table summary="Features offered by the AbstractController" style="border-spacing:0px; line-height:1.6; border-width:0.5pt; border-style:solid; border-color:initial; border-collapse:collapse; width:1150px"> 
           <colgroup> 
            <col class="col_1"/> 
            <col class="col_2"/> 
           </colgroup> 
           <thead style="background:rgb(245,245,245)"> 
            <tr style="border:none"> 
             <th align="left" valign="top" style="padding:6px 13px; border-right:0.5pt solid; border-bottom:0.5pt solid; border-top:none!important; border-left:none!important"> Parameter</th> 
             <th align="left" valign="top" style="padding:6px 13px; border-bottom:0.5pt solid; border-top:none!important; border-right:none!important; border-left:none!important"> Explanation</th> 
            </tr> 
           </thead> 
           <tbody> 
            <tr style="border:none"> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">requireSession</code></p> </td> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">Indicates whether or not this <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> requires a session to do its work. This feature is offered to all controllers. If a session is not present when such a controller receives a request, the user is informed using a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">SessionRequiredException</code>.</p> </td> 
            </tr> 
            <tr style="border:none; background-color:rgb(248,248,248)"> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">synchronizeSession</code></p> </td> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">Use this if you want handling by this controller to be synchronized on the user’s session. To be more specific, the extending controller will override the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleRenderRequestInternal(..)</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleActionRequestInternal(..)</code> methods, which will be synchronized on the user’s session if you specify this variable.</p> </td> 
            </tr> 
            <tr style="border:none"> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">renderWhenMinimized</code></p> </td> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:none!important; border-bottom:0.5pt solid; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px">If you want your controller to actually render the view when the portlet is in a minimized state, set this to true. By default, this is set to false so that portlets that are in a minimized state don’t display any content.</p> </td> 
            </tr> 
            <tr style="border:none; background-color:rgb(248,248,248)"> 
             <td align="left" valign="top" style="padding:6px 7px; border-top:none!important; border-right:0.5pt solid; border-bottom:none!important; border-left:none!important"> <p style="margin-top:0px; margin-bottom:0px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">cacheSeconds</code></p> </td> 
             <td align="left" valign="top" style="padding:6px 7px; border:none!important"> <p style="margin-top:0px; margin-bottom:0px">When you want a controller to override the default cache expiration defined for the portlet, specify a positive integer here. By default it is set to <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">-1</code>, which does not change the default caching. Setting it to <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">0</code> will ensure the result is never cached.</p> </td> 
            </tr> 
           </tbody> 
          </table> 
         </div> 
        </div> 
        <br class="table-break"/> 
        <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">requireSession</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">cacheSeconds</code> properties are declared on the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletContentGenerator</code> class, which is the superclass of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractController</code>) but are included here for completeness.</p> 
        <p style="margin-top:15px; margin-bottom:15px">When using the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractController</code> as a base class for your controllers (which is not recommended since there are a lot of other controllers that might already do the job for you) you only have to override either the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleActionRequestInternal(ActionRequest, ActionResponse)</code> method or the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleRenderRequestInternal(RenderRequest, RenderResponse)</code> method (or both), implement your logic, and return a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ModelAndView</code> object (in the case of<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleRenderRequestInternal</code>).</p> 
        <p style="margin-top:15px; margin-bottom:15px">The default implementations of both <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleActionRequestInternal(..)</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">handleRenderRequestInternal(..)</code> throw a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletException</code>. This is consistent with the behavior of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">GenericPortlet</code> from the JSR- 168 Specification API. So you only need to override the method that your controller is intended to handle.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Here is short example consisting of a class and a declaration in the web application context.</p> 
        <pre><code liberation="" mono=""><span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">package</span> samples;

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">import</span> javax.portlet.RenderRequest;
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">import</span> javax.portlet.RenderResponse;

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">import</span> org.springframework.web.portlet.mvc.AbstractController;
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">import</span> org.springframework.web.portlet.ModelAndView;

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> SampleController <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">extends</span> AbstractController {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) {
        ModelAndView mav = <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> ModelAndView(<span class="hl-string" style="color:rgb(42,0,255)">"foo"</span>);
        mav.addObject(<span class="hl-string" style="color:rgb(42,0,255)">"message"</span>, <span class="hl-string" style="color:rgb(42,0,255)">"Hello World!"</span>);
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> mav;
    }

}</code></pre> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">id</span>=<span class="hl-value" style="color:rgb(42,0,255)">"sampleController"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"samples.SampleController"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"cacheSeconds"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"120"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></property></span></bean></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">The class above and the declaration in the web application context is all you need besides setting up a handler mapping (see Section 19.5, “Handler mappings”) to get this very simple controller working.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.4.2 Other simple controllers</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Although you can extend <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractController</code>, Spring Portlet MVC provides a number of concrete implementations which offer functionality that is commonly used in simple MVC applications.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ParameterizableViewController</code> is basically the same as the example above, except for the fact that you can specify the view name that it will return in the web application context (no need to hard-code the view name).</p> 
        <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletModeNameViewController</code> uses the current mode of the portlet as the view name. So, if your portlet is in View mode (i.e. <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMode.VIEW</code>) then it uses "view" as the view name.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.4.3 Command Controllers</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Spring Portlet MVC has the exact same hierarchy of <span class="emphasis"><em>command controllers</em></span> as Spring Web MVC. They provide a way to interact with data objects and dynamically bind parameters from the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletRequest</code> to the data object specified. Your data objects don’t have to implement a framework-specific interface, so you can directly manipulate your persistent objects if you desire. Let’s examine what command controllers are available, to get an overview of what you can do with them:</p> 
        <div class="itemizedlist" style="margin:0pt"> 
         <ul class="itemizedlist" style="padding-left:30px"> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractCommandController</code> - a command controller you can use to create your own command controller, capable of binding request parameters to a data object you specify. This class does not offer form functionality, it does however offer validation features and lets you specify in the controller itself what to do with the command object that has been filled with the parameters from the request.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractFormController</code> - an abstract controller offering form submission support. Using this controller you can model forms and populate them using a command object you retrieve in the controller. After a user has filled the form, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractFormController</code> binds the fields, validates, and hands the object back to the controller to take appropriate action. Supported features are: invalid form submission (resubmission), validation, and normal form workflow. You implement methods to determine which views are used for form presentation and success. Use this controller if you need forms, but don’t want to specify what views you’re going to show the user in the application context.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">SimpleFormController</code> - a concrete <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractFormController</code> that provides even more support when creating a form with a corresponding command object. The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">SimpleFormController</code> lets you specify a command object, a viewname for the form, a viewname for the page you want to show the user when form submission has succeeded, and more.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractWizardFormController</code> — a concrete <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractFormController</code> that provides a wizard-style interface for editing the contents of a command object across multiple display pages. Supports multiple user actions: finish, cancel, or page change, all of which are easily specified in request parameters from the view.</li> 
         </ul> 
        </div> 
        <p style="margin-top:15px; margin-bottom:15px">These command controllers are quite powerful, but they do require a detailed understanding of how they operate in order to use them efficiently. Carefully review the javadocs for this entire hierarchy and then look at some sample implementations before you start using them.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.4.4 PortletWrappingController</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Instead of developing new controllers, it is possible to use existing portlets and map requests to them from a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>. Using the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletWrappingController</code>, you can instantiate an existing <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Portlet</code> as a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Controller</code> as follows:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">id</span>=<span class="hl-value" style="color:rgb(42,0,255)">"myPortlet"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.mvc.PortletWrappingController"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletClass"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"sample.MyPortlet"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletName"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"my-portlet"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"initParameters"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"><value/></span>config=/WEB-INF/my-portlet-config.xml<span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/></property></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></property></span></property></span></bean></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">This can be very valuable since you can then use interceptors to pre-process and post-process requests going to these portlets. Since JSR-168 does not support any kind of filter mechanism, this is quite handy. For example, this can be used to wrap the Hibernate <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">OpenSessionInViewInterceptor</code> around a MyFaces JSF Portlet.</p> 
       </div> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.5 Handler mappings</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">Using a handler mapping you can map incoming portlet requests to appropriate handlers. There are some handler mappings you can use out of the box, for example, the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletModeHandlerMapping</code>, but let’s first examine the general concept of a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerMapping</code>.</p> 
       <p style="margin-top:15px; margin-bottom:15px">Note: We are intentionally using the term "Handler" here instead of "Controller". <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> is designed to be used with other ways to process requests than just Spring Portlet MVC’s own Controllers. A Handler is any Object that can handle portlet requests. Controllers are an example of Handlers, and they are of course the default. To use some other framework with <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>, a corresponding implementation of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerAdapter</code> is all that is needed.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The functionality a basic <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerMapping</code> provides is the delivering of a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerExecutionChain</code>, which must contain the handler that matches the incoming request, and may also contain a list of handler interceptors that are applied to the request. When a request comes in, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> will hand it over to the handler mapping to let it inspect the request and come up with an appropriate <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerExecutionChain</code>. Then the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> will execute the handler and interceptors in the chain (if any). These concepts are all exactly the same as in Spring Web MVC.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The concept of configurable handler mappings that can optionally contain interceptors (executed before or after the actual handler was executed, or both) is extremely powerful. A lot of supporting functionality can be built into a custom <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerMapping</code>. Think of a custom handler mapping that chooses a handler not only based on the portlet mode of the request coming in, but also on a specific state of the session associated with the request.</p> 
       <p style="margin-top:15px; margin-bottom:15px">In Spring Web MVC, handler mappings are commonly based on URLs. Since there is really no such thing as a URL within a Portlet, we must use other mechanisms to control mappings. The two most common are the portlet mode and a request parameter, but anything available to the portlet request can be used in a custom handler mapping.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The rest of this section describes three of Spring Portlet MVC’s most commonly used handler mappings. They all extend <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AbstractHandlerMapping</code> and share the following properties:</p> 
       <div class="itemizedlist" style="margin:0pt"> 
        <ul class="itemizedlist" style="padding-left:30px"> 
         <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">interceptors</code>: The list of interceptors to use. <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerInterceptor</code>s are discussed in Section 19.5.4, “Adding HandlerInterceptors”.</li> 
         <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">defaultHandler</code>: The default handler to use, when this handler mapping does not result in a matching handler.</li> 
         <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">order</code>: Based on the value of the order property (see the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.core.Ordered</code> interface), Spring will sort all handler mappings available in the context and apply the first matching handler.</li> 
         <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">lazyInitHandlers</code>: Allows for lazy initialization of singleton handlers (prototype handlers are always lazily initialized). Default value is false. This property is directly implemented in the three concrete Handlers.</li> 
        </ul> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.1 PortletModeHandlerMapping</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">This is a simple handler mapping that maps incoming requests based on the current mode of the portlet (e.g. <span class="emphasis"><em>view</em></span>, <span class="emphasis"><em>edit</em></span>, <span class="emphasis"><em>help</em></span>). An example:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.handler.PortletModeHandlerMapping"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletModeMap"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"view"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"viewHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"edit"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"editHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"help"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"helpHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span></entry></span></entry></span></property></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></bean></span></code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.2 ParameterHandlerMapping</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">If we need to navigate around to multiple controllers without changing portlet mode, the simplest way to do this is with a request parameter that is used as the key to control the mapping.</p> 
        <p style="margin-top:15px; margin-bottom:15px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ParameterHandlerMapping</code> uses the value of a specific request parameter to control the mapping. The default name of the parameter is <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">'action'</code>, but can be changed using the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">'parameterName'</code> property.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The bean configuration for this mapping will look something like this:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.handler.ParameterHandlerMapping"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"parameterMap"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"add"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"addItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"edit"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"editItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"delete"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"deleteItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span></entry></span></entry></span></property></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></bean></span></code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.3 PortletModeParameterHandlerMapping</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The most powerful built-in handler mapping, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletModeParameterHandlerMapping</code> combines the capabilities of the two previous ones to allow different navigation within each portlet mode.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Again the default name of the parameter is "action", but can be changed using the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">parameterName</code> property.</p> 
        <p style="margin-top:15px; margin-bottom:15px">By default, the same parameter value may not be used in two different portlet modes. This is so that if the portal itself changes the portlet mode, the request will no longer be valid in the mapping. This behavior can be changed by setting the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">allowDupParameters</code> property to true. However, this is not recommended.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The bean configuration for this mapping will look something like this:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletModeParameterMap"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"view"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic"><!-- </span><span class="emphasis"><em>view</em></span> portlet mode -->
                <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
                    <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"add"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"addItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
                    <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"edit"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"editItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
                    <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"delete"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"deleteItemHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
                <span class="hl-tag" style="color:rgb(63,127,127)"/>
            <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"edit"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic"><!-- </span><span class="emphasis"><em>edit</em></span> portlet mode -->
                <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
                    <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"prefs"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"prefsHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
                    <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"resetPrefs"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"resetPrefsHandler"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
                <span class="hl-tag" style="color:rgb(63,127,127)"/>
            <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span></span></entry></span></entry></span></entry></span></span></entry></span></property></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></bean></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">This mapping can be chained ahead of a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletModeHandlerMapping</code>, which can then provide defaults for each mode and an overall default as well.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.4 Adding HandlerInterceptors</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Spring’s handler mapping mechanism has a notion of handler interceptors, which can be extremely useful when you want to apply specific functionality to certain requests, for example, checking for a principal. Again Spring Portlet MVC implements these concepts in the same way as Web MVC.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Interceptors located in the handler mapping must implement <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerInterceptor</code> from the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.portlet</code> package. Just like the servlet version, this interface defines three methods: one that will be called before the actual handler will be executed ( <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">preHandle</code>), one that will be called after the handler is executed ( <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">postHandle</code>), and one that is called after the complete request has finished ( <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">afterCompletion</code>). These three methods should provide enough flexibility to do all kinds of pre- and post- processing.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">preHandle</code> method returns a boolean value. You can use this method to break or continue the processing of the execution chain. When this method returns <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">true</code>, the handler execution chain will continue. When it returns <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">false</code>, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> assumes the interceptor itself has taken care of requests (and, for example, rendered an appropriate view) and does not continue executing the other interceptors and the actual handler in the execution chain.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">postHandle</code> method is only called on a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code>. The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">preHandle</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">afterCompletion</code> methods are called on both an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code> and a<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code>. If you need to execute logic in these methods for just one type of request, be sure to check what kind of request it is before processing it.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.5 HandlerInterceptorAdapter</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">As with the servlet package, the portlet package has a concrete implementation of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerInterceptor</code> called <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerInterceptorAdapter</code>. This class has empty versions of all the methods so that you can inherit from this class and implement just one or two methods when that is all you need.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.5.6 ParameterMappingInterceptor</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The portlet package also has a concrete interceptor named <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ParameterMappingInterceptor</code> that is meant to be used directly with <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ParameterHandlerMapping</code> and<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletModeParameterHandlerMapping</code>. This interceptor will cause the parameter that is being used to control the mapping to be forwarded from an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code>to the subsequent <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code>. This will help ensure that the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code> is mapped to the same Handler as the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code>. This is done in the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">preHandle</code> method of the interceptor, so you can still modify the parameter value in your handler to change where the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code> will be mapped.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Be aware that this interceptor is calling <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">setRenderParameter</code> on the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionResponse</code>, which means that you cannot call <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">sendRedirect</code> in your handler when using this interceptor. If you need to do external redirects then you will either need to forward the mapping parameter manually or write a different interceptor to handle this for you.</p> 
       </div> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.6 Views and resolving them</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">As mentioned previously, Spring Portlet MVC directly reuses all the view technologies from Spring Web MVC. This includes not only the various <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code> implementations themselves, but also the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewResolver</code> implementations. For more information, refer to Chapter 17, <em>    </em> and Section 16.5, “    ” respectively.</p> 
       <p style="margin-top:15px; margin-bottom:15px">A few items on using the existing <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewResolver</code> implementations are worth mentioning:</p> 
       <div class="itemizedlist" style="margin:0pt"> 
        <ul class="itemizedlist" style="padding-left:30px"> 
         <li class="listitem">Most portals expect the result of rendering a portlet to be an HTML fragment. So, things like JSP/JSTL, Velocity, FreeMarker, and XSLT all make sense. But it is unlikely that views that return other document types will make any sense in a portlet context.</li> 
         <li class="listitem">There is no such thing as an HTTP redirect from within a portlet (the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">sendRedirect(..)</code> method of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionResponse</code> cannot be used to stay within the portal). So,<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RedirectView</code> and use of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">'redirect:'</code> prefix will <span class="emphasis"><em>not</em></span> work correctly from within Portlet MVC.</li> 
         <li class="listitem">It may be possible to use the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">'forward:'</code> prefix from within Portlet MVC. However, remember that since you are in a portlet, you have no idea what the current URL looks like. This means you cannot use a relative URL to access other resources in your web application and that you will have to use an absolute URL.</li> 
        </ul> 
       </div> 
       <p style="margin-top:15px; margin-bottom:15px">Also, for JSP development, the new Spring Taglib and the new Spring Form Taglib both work in portlet views in exactly the same way that they work in servlet views.</p> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.7 Multipart (file upload) support</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">Spring Portlet MVC has built-in multipart support to handle file uploads in portlet applications, just like Web MVC does. The design for the multipart support is done with pluggable <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMultipartResolver</code> objects, defined in the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.portlet.multipart</code> package. Spring provides a<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMultipartResolver</code> for use with Commons FileUpload. How uploading files is supported will be described in the rest of this section.</p> 
       <p style="margin-top:15px; margin-bottom:15px">By default, no multipart handling will be done by Spring Portlet MVC, as some developers will want to handle multiparts themselves. You will have to enable it yourself by adding a multipart resolver to the web application’s context. After you have done that, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> will inspect each request to see if it contains a multipart. If no multipart is found, the request will continue as expected. However, if a multipart is found in the request, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMultipartResolver</code> that has been declared in your context will be used. After that, the multipart attribute in your request will be treated like any other attribute.</p> 
       <div class="note" style="margin:20px 0.5in; padding-top:10px; padding-bottom:10px"> 
        <table border="0" summary="Note" style="border-spacing:0px; line-height:1.6; margin:0px; border:none!important; background:none!important"> 
         <tbody style="margin:0px; border:none!important; background:none!important"> 
          <tr style="border:none!important; margin:0px; background:none!important"> 
           <td rowspan="2" align="center" valign="top" width="25" style="padding:10px 13px 6px; border-top:none!important; border-right:1px solid rgb(204,204,204)!important; border-bottom:none!important; border-left:none!important; margin:0px; background:none!important"> </td> 
          </tr> 
          <tr style="border:none!important; margin:0px; background-color:rgb(248,248,248)"> 
           <td align="left" valign="top" style="padding:6px 13px; border:none!important; margin:0px; background:none!important"> <p style="margin-top:0px; margin-bottom:0px; color:rgb(111,111,111); line-height:1.6; border:none!important; background:none!important"> Any configured <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">PortletMultipartResolver</code> bean <span class="emphasis" style="margin:0px; border:none!important; background:none!important"><span style="margin:0px; border:none!important; background:none!important">must</span></span> have the following id (or name): " <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">portletMultipartResolver</code>". If you have defined your<code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">PortletMultipartResolver</code> with any other name, then the <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">DispatcherPortlet</code> will <span class="emphasis" style="margin:0px; border:none!important; background:none!important"><span style="margin:0px; border:none!important; background:none!important">not</span></span> find your <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">PortletMultipartResolver</code>, and consequently no multipart support will be in effect.</p> </td> 
          </tr> 
         </tbody> 
        </table> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.7.1 Using the PortletMultipartResolver</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The following example shows how to use the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">CommonsPortletMultipartResolver</code>:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">id</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletMultipartResolver"</span>
        <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic"><!-- one of the properties available; the maximum file size in bytes --></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"maxUploadSize"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"100000"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></property></span></bean></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">Of course you also need to put the appropriate jars in your classpath for the multipart resolver to work. In the case of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">CommonsMultipartResolver</code>, you need to use<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">commons-fileupload.jar</code>. Be sure to use at least version 1.1 of Commons FileUpload as previous versions do not support JSR-168 Portlet applications.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Now that you have seen how to set Portlet MVC up to handle multipart requests, let’s talk about how to actually use it. When <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code> detects a multipart request, it activates the resolver that has been declared in your context and hands over the request. What the resolver then does is wrap the current <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code> in a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">MultipartActionRequest</code> that has support for multipart file uploads. Using the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">MultipartActionRequest</code> you can get information about the multiparts contained by this request and actually get access to the multipart files themselves in your controllers.</p> 
        <p style="margin-top:15px; margin-bottom:15px">Note that you can only receive multipart file uploads as part of an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ActionRequest</code>, not as part of a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RenderRequest</code>.</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.7.2 Handling a file upload in a form</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">After the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMultipartResolver</code> has finished doing its job, the request will be processed like any other. To use the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletMultipartResolver</code>, create a form with an upload field (see example below), then let Spring bind the file onto your form (backing object). To actually let the user upload a file, we have to create a (JSP/HTML) form:</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><h1/></span>Please upload a file<span class="hl-tag" style="color:rgb(63,127,127)"/>
<span class="hl-tag" style="color:rgb(63,127,127)"><form> <span class="hl-attribute" style="color:rgb(127,0,127)">method</span>=<span class="hl-value" style="color:rgb(42,0,255)">"post"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">action</span>=<span class="hl-value" style="color:rgb(42,0,255)">"<actionurl/>"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">enctype</span>=<span class="hl-value" style="color:rgb(42,0,255)">"multipart/form-data"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><input/> <span class="hl-attribute" style="color:rgb(127,0,127)">type</span>=<span class="hl-value" style="color:rgb(42,0,255)">"file"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"file"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><input/> <span class="hl-attribute" style="color:rgb(127,0,127)">type</span>=<span class="hl-value" style="color:rgb(42,0,255)">"submit"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></span></span></form></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">As you can see, we’ve created a field named "file" that matches the property of the bean that holds the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">byte[]</code> array. Furthermore we’ve added the encoding attribute (<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">enctype="multipart/form-data"</code>), which is necessary to let the browser know how to encode the multipart fields (do not forget this!).</p> 
        <p style="margin-top:15px; margin-bottom:15px">Just as with any other property that’s not automagically convertible to a string or primitive type, to be able to put binary data in your objects you have to register a custom editor with the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">PortletRequestDataBinder</code>. There are a couple of editors available for handling files and setting the results on an object. There’s a<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">StringMultipartFileEditor</code> capable of converting files to Strings (using a user-defined character set), and there is a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ByteArrayMultipartFileEditor</code> which converts files to byte arrays. They function analogous to the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">CustomDateEditor</code>.</p> 
        <p style="margin-top:15px; margin-bottom:15px">So, to be able to upload files using a form, declare the resolver, a mapping to a controller that will process the bean, and the controller itself.</p> 
        <pre><code liberation="" mono=""><span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">id</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletMultipartResolver"</span>
        <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>

<span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.handler.PortletModeHandlerMapping"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"portletModeMap"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"><map/></span>
            <span class="hl-tag" style="color:rgb(63,127,127)"><entry> <span class="hl-attribute" style="color:rgb(127,0,127)">key</span>=<span class="hl-value" style="color:rgb(42,0,255)">"view"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value-ref</span>=<span class="hl-value" style="color:rgb(42,0,255)">"fileUploadController"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
        <span class="hl-tag" style="color:rgb(63,127,127)"/>
    <span class="hl-tag" style="color:rgb(63,127,127)"/></entry></span></property></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></bean></span>

<span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">id</span>=<span class="hl-value" style="color:rgb(42,0,255)">"fileUploadController"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"examples.FileUploadController"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"commandClass"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"examples.FileUploadBean"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"formView"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"fileuploadform"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
    <span class="hl-tag" style="color:rgb(63,127,127)"><property> <span class="hl-attribute" style="color:rgb(127,0,127)">name</span>=<span class="hl-value" style="color:rgb(42,0,255)">"successView"</span> <span class="hl-attribute" style="color:rgb(127,0,127)">value</span>=<span class="hl-value" style="color:rgb(42,0,255)">"confirmation"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>
<span class="hl-tag" style="color:rgb(63,127,127)"/></property></span></property></span></property></span></bean></span></bean></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">After that, create the controller and the actual class to hold the file property.</p> 
        <pre><code liberation="" mono=""><span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadController <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">extends</span> SimpleFormController {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> onSubmitAction(ActionRequest request, ActionResponse response,
            Object command, BindException errors) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception {

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// cast the bean</span>
        FileUploadBean bean = (FileUploadBean) command;

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// let's see if there's content there</span>
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">byte</span>[] file = bean.getFile();
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (file == null) {
            <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// hmm, that's strange, the user did not upload anything</span>
        }

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// do something with the file here</span>
    }

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">protected</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> initBinder(PortletRequest request,
            PortletRequestDataBinder binder) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception {
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// to actually be able to convert Multipart instance to byte[]</span>
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// we have to register a custom editor</span>
        binder.registerCustomEditor(<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">byte</span>[].<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span>, <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> ByteArrayMultipartFileEditor());
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// now Spring knows how to handle multipart object and convert</span>
    }

}

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadBean {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">private</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">byte</span>[] file;

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> setFile(<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">byte</span>[] file) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.file = file;
    }

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">byte</span>[] getFile() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> file;
    }

}</code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">As you can see, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">FileUploadBean</code> has a property of type <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">byte[]</code> that holds the file. The controller registers a custom editor to let Spring know how to actually convert the multipart objects the resolver has found to properties specified by the bean. In this example, nothing is done with the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">byte[]</code> property of the bean itself, but in practice you can do whatever you want (save it in a database, mail it to somebody, etc).</p> 
        <p style="margin-top:15px; margin-bottom:15px">An equivalent example in which a file is bound straight to a String-typed property on a form backing object might look like this:</p> 
        <pre><code liberation="" mono=""><span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadController <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">extends</span> SimpleFormController {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> onSubmitAction(ActionRequest request, ActionResponse response,
            Object command, BindException errors) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception {

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// cast the bean</span>
        FileUploadBean bean = (FileUploadBean) command;

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// let's see if there's content there</span>
        String file = bean.getFile();
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (file == null) {
            <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// hmm, that's strange, the user did not upload anything</span>
        }

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// do something with the file here</span>
    }

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">protected</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> initBinder(PortletRequest request,
            PortletRequestDataBinder binder) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception {

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// to actually be able to convert Multipart instance to a String</span>
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// we have to register a custom editor</span>
        binder.registerCustomEditor(String.<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span>, <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> StringMultipartFileEditor());
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// now Spring knows how to handle multipart objects and convert</span>
    }
}

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadBean {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">private</span> String file;

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> setFile(String file) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.file = file;
    }

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> String getFile() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> file;
    }
}</code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">Of course, this last example only makes (logical) sense in the context of uploading a plain text file (it wouldn’t work so well in the case of uploading an image file).</p> 
        <p style="margin-top:15px; margin-bottom:15px">The third (and final) option is where one binds directly to a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">MultipartFile</code> property declared on the (form backing) object’s class. In this case one does not need to register any custom property editor because there is no type conversion to be performed.</p> 
        <pre><code liberation="" mono=""><span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadController <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">extends</span> SimpleFormController {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> onSubmitAction(ActionRequest request, ActionResponse response,
            Object command, BindException errors) <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">throws</span> Exception {

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// cast the bean</span>
        FileUploadBean bean = (FileUploadBean) command;

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// let's see if there's content there</span>
        MultipartFile file = bean.getFile();
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (file == null) {
            <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// hmm, that's strange, the user did not upload anything</span>
        }

        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// do something with the file here</span>
    }
}

<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> FileUploadBean {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">private</span> MultipartFile file;

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> setFile(MultipartFile file) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.file = file;
    }

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> MultipartFile getFile() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> file;
    }

}</code></pre> 
       </div> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.8 Handling exceptions</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">Just like Servlet MVC, Portlet MVC provides <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerExceptionResolver</code>s to ease the pain of unexpected exceptions that occur while your request is being processed by a handler that matched the request. Portlet MVC also provides a portlet-specific, concrete <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">SimpleMappingExceptionResolver</code> that enables you to take the class name of any exception that might be thrown and map it to a view name.</p> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.9 Annotation-based controller configuration</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">Spring 2.5 introduced an annotation-based programming model for MVC controllers, using annotations such as <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code>, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestParam</code>,<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code>, etc. This annotation support is available for both Servlet MVC and Portlet MVC. Controllers implemented in this style do not have to extend specific base classes or implement specific interfaces. Furthermore, they do not usually have direct dependencies on Servlet or Portlet API’s, although they can easily get access to Servlet or Portlet facilities if desired.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The following sections document these annotations and how they are most commonly used in a Portlet environment.</p> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.1 Setting up the dispatcher for annotation support</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px"><span class="emphasis"><em>`@RequestMapping` will only be processed if a corresponding <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerMapping</code> (for type level annotations) and/or <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerAdapter</code> (for method level annotations) is present in the dispatcher.</em></span> This is the case by default in both <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherServlet</code> and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DispatcherPortlet</code>.</p> 
        <p style="margin-top:15px; margin-bottom:15px">However, if you are defining custom <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerMappings</code> or <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">HandlerAdapters</code>, then you need to make sure that a corresponding custom<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DefaultAnnotationHandlerMapping</code> and/or <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AnnotationMethodHandlerAdapter</code> is defined as well - provided that you intend to use <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code>.</p> 
        <pre><code liberation="" mono=""><span class="hl-directive" style="color:maroon"><?xml version="1.0" encoding="UTF-8"??></span>
<span class="hl-tag" style="color:rgb(63,127,127)"><beans> <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.springframework.org/schema/beans"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns:xsi</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.w3.org/2001/XMLSchema-instance"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xsi:schemaLocation</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>

    <span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>

    <span class="hl-tag" style="color:rgb(63,127,127)"><bean> <span class="hl-attribute" style="color:rgb(127,0,127)">class</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>

    // ... (controller bean definitions) ...

<span class="hl-tag" style="color:rgb(63,127,127)"/></bean></span></bean></span></beans></span></code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">Defining a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">DefaultAnnotationHandlerMapping</code> and/or <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AnnotationMethodHandlerAdapter</code> explicitly also makes sense if you would like to customize the mapping strategy, e.g. specifying a custom <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebBindingInitializer</code> (see below).</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.2 Defining a controller with @Controller</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@Controller</code> annotation indicates that a particular class serves the role of a <span class="emphasis"><em>controller</em></span>. There is no need to extend any controller base class or reference the Portlet API. You are of course still able to reference Portlet-specific features if you need to.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The basic purpose of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@Controller</code> annotation is to act as a stereotype for the annotated class, indicating its role. The dispatcher will scan such annotated classes for mapped methods, detecting <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code> annotations (see the next section).</p> 
        <p style="margin-top:15px; margin-bottom:15px">Annotated controller beans may be defined explicitly, using a standard Spring bean definition in the dispatcher’s context. However, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@Controller</code> stereotype also allows for autodetection, aligned with Spring 2.5’s general support for detecting component classes in the classpath and auto-registering bean definitions for them.</p> 
        <p style="margin-top:15px; margin-bottom:15px">To enable autodetection of such annotated controllers, you have to add component scanning to your configuration. This is easily achieved by using the <span class="emphasis"><em>spring-context</em></span>schema as shown in the following XML snippet:</p> 
        <pre><code liberation="" mono=""><span class="hl-directive" style="color:maroon"><?xml version="1.0" encoding="UTF-8"??></span>
<span class="hl-tag" style="color:rgb(63,127,127)"><beans> <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.springframework.org/schema/beans"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns:xsi</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.w3.org/2001/XMLSchema-instance"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns:p</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.springframework.org/schema/p"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xmlns:context</span>=<span class="hl-value" style="color:rgb(42,0,255)">"http://www.springframework.org/schema/context"</span>
    <span class="hl-attribute" style="color:rgb(127,0,127)">xsi:schemaLocation</span>=<span class="hl-value" style="color:rgb(42,0,255)">"
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd"</span><span class="hl-tag" style="color:rgb(63,127,127)">></span>

    <span class="hl-tag" style="color:rgb(63,127,127)"><component-scan> <span class="hl-attribute" style="color:rgb(127,0,127)">base-package</span>=<span class="hl-value" style="color:rgb(42,0,255)">"org.springframework.samples.petportal.portlet"</span><span class="hl-tag" style="color:rgb(63,127,127)">/></span>

    // ...

<span class="hl-tag" style="color:rgb(63,127,127)"/></component-scan></span></beans></span></code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.3 Mapping requests with @RequestMapping</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code> annotation is used to map portlet modes like <span class="emphasis"><em>VIEW</em></span>/<span class="emphasis"><em>EDIT</em></span> onto an entire class or a particular handler method. Typically the type-level annotation maps a specific mode (or mode plus parameter condition) onto a form controller, with additional method-level annotations <span class="emphasis"><em>narrowing</em></span> the primary mapping for specific portlet request parameters.</p> 
        <div class="tip" style="margin:20px 0.5in; padding-top:10px; padding-bottom:10px"> 
         <table border="0" summary="Tip" style="border-spacing:0px; line-height:1.6; margin:0px; border:none!important; background:none!important"> 
          <tbody style="margin:0px; border:none!important; background:none!important"> 
           <tr style="border:none!important; margin:0px; background:none!important"> 
            <td rowspan="2" align="center" valign="top" width="25" style="padding:10px 13px 6px; border-top:none!important; border-right:1px solid rgb(204,204,204)!important; border-bottom:none!important; border-left:none!important; margin:0px; background:none!important"> </td> 
           </tr> 
           <tr style="border:none!important; margin:0px; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 13px; border:none!important; margin:0px; background:none!important"> <p style="margin-top:0px; margin-bottom:0px; color:rgb(111,111,111); line-height:1.6; border:none!important; background:none!important"> <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">@RequestMapping</code> at the type level may be used for plain implementations of the <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">Controller</code> interface as well. In this case, the request processing code would follow the traditional <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">handle(Action|Render)Request</code> signature, while the controller’s mapping would be expressed through an<code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">@RequestMapping</code> annotation. This works for pre-built <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">Controller</code> base classes, such as <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">SimpleFormController</code>, too.</p> <p style="margin-top:0px; margin-bottom:0px; color:rgb(111,111,111); line-height:1.6; border:none!important; background:none!important"> In the following discussion, we’ll focus on controllers that are based on annotated handler methods.</p> </td> 
           </tr> 
          </tbody> 
         </table> 
        </div> 
        <p style="margin-top:15px; margin-bottom:15px">The following is an example of a form controller from the PetPortal sample application using this annotation:</p> 
        <pre><code liberation="" mono=""><em><span class="hl-annotation" style="color:gray">@Controller</span>
<span class="hl-annotation" style="color:gray">@RequestMapping("EDIT")</span>
<span class="hl-annotation" style="color:gray">@SessionAttributes("site")</span></em>
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> PetSitesEditController {

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">private</span> Properties petSites;

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> setPetSites(Properties petSites) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites = petSites;
    }

    <em><span class="hl-annotation" style="color:gray">@ModelAttribute("petSites")</span></em>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> Properties getPetSites() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites;
    }

    <em><span class="hl-annotation" style="color:gray">@RequestMapping</span></em> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// default (action=list)</span>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> String showPetSites() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> <span class="hl-string" style="color:rgb(42,0,255)">"petSitesEdit"</span>;
    }

    <em><span class="hl-annotation" style="color:gray">@RequestMapping(params = "action=add")</span></em> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// render phase</span>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> String showSiteForm(Model model) {
        <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// Used for the initial form as well as for redisplaying with errors.</span>
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (!model.containsAttribute(<span class="hl-string" style="color:rgb(42,0,255)">"site"</span>)) {
            model.addAttribute(<span class="hl-string" style="color:rgb(42,0,255)">"site"</span>, <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> PetSite());
        }

        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> <span class="hl-string" style="color:rgb(42,0,255)">"petSitesAdd"</span>;
    }

    <em><span class="hl-annotation" style="color:gray">@RequestMapping(params = "action=add")</span></em> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// action phase</span>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> populateSite(<em><span class="hl-annotation" style="color:gray">@ModelAttribute("site")</span></em> PetSite petSite,
            BindingResult result, SessionStatus status, ActionResponse response) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> PetSiteValidator().validate(petSite, result);
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (!result.hasErrors()) {
            <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites.put(petSite.getName(), petSite.getUrl());
            status.setComplete();
            response.setRenderParameter(<span class="hl-string" style="color:rgb(42,0,255)">"action"</span>, <span class="hl-string" style="color:rgb(42,0,255)">"list"</span>);
        }
    }

    <em><span class="hl-annotation" style="color:gray">@RequestMapping(params = "action=delete")</span></em>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> removeSite(<em><span class="hl-annotation" style="color:gray">@RequestParam("site")</span></em> String site, ActionResponse response) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites.remove(site);
        response.setRenderParameter(<span class="hl-string" style="color:rgb(42,0,255)">"action"</span>, <span class="hl-string" style="color:rgb(42,0,255)">"list"</span>);
    }
}</code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.4 Supported handler method arguments</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">Handler methods which are annotated with <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code> are allowed to have very flexible signatures. They may have arguments of the following types, in arbitrary order (except for validation results, which need to follow right after the corresponding command object, if desired):</p> 
        <div class="itemizedlist" style="margin:0pt"> 
         <ul class="itemizedlist" style="padding-left:30px"> 
          <li class="listitem">Request and/or response objects (Portlet API). You may choose any specific request/response type, e.g. PortletRequest / ActionRequest / RenderRequest. An explicitly declared action/render argument is also used for mapping specific request types onto a handler method (in case of no other information given that differentiates between action and render requests).</li> 
          <li class="listitem">Session object (Portlet API): of type PortletSession. An argument of this type will enforce the presence of a corresponding session. As a consequence, such an argument will never be <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">null</code>.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.context.request.WebRequest</code> or <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.context.request.NativeWebRequest</code>. Allows for generic request parameter access as well as request/session attribute access, without ties to the native Servlet/Portlet API.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.util.Locale</code> for the current request locale (the portal locale in a Portlet environment).</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.util.TimeZone</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.time.ZoneId</code> for the current request time zone.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.io.InputStream</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.io.Reader</code> for access to the request’s content. This will be the raw InputStream/Reader as exposed by the Portlet API.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.io.OutputStream</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.io.Writer</code> for generating the response’s content. This will be the raw OutputStream/Writer as exposed by the Portlet API.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestParam</code> annotated parameters for access to specific Portlet request parameters. Parameter values will be converted to the declared method argument type.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.util.Map</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.ui.Model</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.ui.ModelMap</code> for enriching the implicit model that will be exposed to the web view.</li> 
          <li class="listitem">Command/form objects to bind parameters to: as bean properties or fields, with customizable type conversion, depending on <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@InitBinder</code> methods and/or the HandlerAdapter configuration - see the " <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">webBindingInitializer</code>" property on <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AnnotationMethodHandlerAdapter</code>. Such command objects along with their validation results will be exposed as model attributes, by default using the non-qualified command class name in property notation (e.g. "orderAddress" for type "mypackage.OrderAddress"). Specify a parameter-level <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ModelAttribute</code> annotation for declaring a specific model attribute name.</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.validation.Errors</code> / <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.validation.BindingResult</code> validation results for a preceding command/form object (the immediate preceding argument).</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">org.springframework.web.bind.support.SessionStatus</code> status handle for marking form processing as complete (triggering the cleanup of session attributes that have been indicated by the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@SessionAttributes</code> annotation at the handler type level).</li> 
         </ul> 
        </div> 
        <p style="margin-top:15px; margin-bottom:15px">The following return types are supported for handler methods:</p> 
        <div class="itemizedlist" style="margin:0pt"> 
         <ul class="itemizedlist" style="padding-left:30px"> 
          <li class="listitem">A <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ModelAndView</code> object, with the model implicitly enriched with command objects and the results of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods.</li> 
          <li class="listitem">A <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Model</code> object, with the view name implicitly determined through a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RequestToViewNameTranslator</code> and the model implicitly enriched with command objects and the results of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods.</li> 
          <li class="listitem">A <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Map</code> object for exposing a model, with the view name implicitly determined through a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">RequestToViewNameTranslator</code> and the model implicitly enriched with command objects and the results of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods.</li> 
          <li class="listitem">A <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">View</code> object, with the model implicitly determined through command objects and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Model</code> argument (see above).</li> 
          <li class="listitem">A <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">String</code> value which is interpreted as view name, with the model implicitly determined through command objects and <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">Model</code> argument (see above).</li> 
          <li class="listitem"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">void</code> if the method handles the response itself (e.g. by writing the response content directly).</li> 
          <li class="listitem">Any other return type will be considered a single model attribute to be exposed to the view, using the attribute name specified through <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> at the method level (or the default attribute name based on the return type’s class name otherwise). The model will be implicitly enriched with command objects and the results of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> annotated reference data accessor methods.</li> 
         </ul> 
        </div> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.5 Binding request parameters to method parameters with @RequestParam</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestParam</code> annotation is used to bind request parameters to a method parameter in your controller.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The following code snippet from the PetPortal sample application shows the usage:</p> 
        <pre><code liberation="" mono=""><em><span class="hl-annotation" style="color:gray">@Controller</span>
<span class="hl-annotation" style="color:gray">@RequestMapping("EDIT")</span>
<span class="hl-annotation" style="color:gray">@SessionAttributes("site")</span></em>
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> PetSitesEditController {

    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// ...</span>

    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> removeSite(<em><span class="hl-annotation" style="color:gray">@RequestParam("site")</span></em> String site, ActionResponse response) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites.remove(site);
        response.setRenderParameter(<span class="hl-string" style="color:rgb(42,0,255)">"action"</span>, <span class="hl-string" style="color:rgb(42,0,255)">"list"</span>);
    }

    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// ...</span>

}</code></pre> 
        <p style="margin-top:15px; margin-bottom:15px">Parameters using this annotation are required by default, but you can specify that a parameter is optional by setting <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestParam</code>'s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">required</code> attribute to <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">false</code>(e.g., <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestParam(value="id", required=false)</code>).</p> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.6 Providing a link to data from the model with @ModelAttribute</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> has two usage scenarios in controllers. When placed on a method parameter, <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> is used to map a model attribute to the specific, annotated method parameter (see the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">populateSite()</code> method below). This is how the controller gets a reference to the object holding the data entered in the form. In addition, the parameter can be declared as the specific type of the form backing object rather than as a generic <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.lang.Object</code>, thus increasing type safety.</p> 
        <p style="margin-top:15px; margin-bottom:15px"><code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@ModelAttribute</code> is also used at the method level to provide <span class="emphasis"><em>reference data</em></span> for the model (see the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">getPetSites()</code> method below). For this usage the method signature can contain the same types as documented above for the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code> annotation.</p> 
        <div class="note" style="margin:20px 0.5in; padding-top:10px; padding-bottom:10px"> 
         <table border="0" summary="Note" style="border-spacing:0px; line-height:1.6; margin:0px; border:none!important; background:none!important"> 
          <tbody style="margin:0px; border:none!important; background:none!important"> 
           <tr style="border:none!important; margin:0px; background:none!important"> 
            <td rowspan="2" align="center" valign="top" width="25" style="padding:10px 13px 6px; border-top:none!important; border-right:1px solid rgb(204,204,204)!important; border-bottom:none!important; border-left:none!important; margin:0px; background:none!important"> </td> 
           </tr> 
           <tr style="border:none!important; margin:0px; background-color:rgb(248,248,248)"> 
            <td align="left" valign="top" style="padding:6px 13px; border:none!important; margin:0px; background:none!important"> <p style="margin-top:0px; margin-bottom:0px; color:rgb(111,111,111); line-height:1.6; border:none!important; background:none!important"> <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">@ModelAttribute</code> annotated methods will be executed <span class="emphasis" style="margin:0px; border:none!important; background:none!important"><span style="margin:0px; border:none!important; background:none!important">before</span></span> the chosen <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">@RequestMapping</code> annotated handler method. They effectively pre-populate the implicit model with specific attributes, often loaded from a database. Such an attribute can then already be accessed through <code liberation="" mono="" color:rgb="" background:none="" rgb="" border:1px="" solid="" padding:1px="" white-space:nowrap="" margin:0px="">@ModelAttribute</code>annotated handler method parameters in the chosen handler method, potentially with binding and validation applied to it.</p> </td> 
           </tr> 
          </tbody> 
         </table> 
        </div> 
        <p style="margin-top:15px; margin-bottom:15px">The following code snippet shows these two usages of this annotation:</p> 
        <pre><code liberation="" mono=""><em><span class="hl-annotation" style="color:gray">@Controller</span>
<span class="hl-annotation" style="color:gray">@RequestMapping("EDIT")</span>
<span class="hl-annotation" style="color:gray">@SessionAttributes("site")</span></em>
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> PetSitesEditController {

    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// ...</span>

    <em><span class="hl-annotation" style="color:gray">@ModelAttribute("petSites")</span></em>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> Properties getPetSites() {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">return</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites;
    }

    <em><span class="hl-annotation" style="color:gray">@RequestMapping(params = "action=add")</span></em> <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// action phase</span>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> populateSite( <em><span class="hl-annotation" style="color:gray">@ModelAttribute("site")</span></em> PetSite petSite, BindingResult result, SessionStatus status, ActionResponse response) {
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> PetSiteValidator().validate(petSite, result);
        <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">if</span> (!result.hasErrors()) {
            <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">this</span>.petSites.put(petSite.getName(), petSite.getUrl());
            status.setComplete();
            response.setRenderParameter(<span class="hl-string" style="color:rgb(42,0,255)">"action"</span>, <span class="hl-string" style="color:rgb(42,0,255)">"list"</span>);
        }
    }
}</code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.7 Specifying attributes to store in a Session with @SessionAttributes</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">The type-level <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@SessionAttributes</code> annotation declares session attributes used by a specific handler. This will typically list the names of model attributes or types of model attributes which should be transparently stored in the session or some conversational storage, serving as form-backing beans between subsequent requests.</p> 
        <p style="margin-top:15px; margin-bottom:15px">The following code snippet shows the usage of this annotation:</p> 
        <pre><code liberation="" mono=""><em><span class="hl-annotation" style="color:gray">@Controller</span>
<span class="hl-annotation" style="color:gray">@RequestMapping("EDIT")</span>
<span class="hl-annotation" style="color:gray">@SessionAttributes("site")</span></em>
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> PetSitesEditController {
    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// ...</span>
}</code></pre> 
       </div> 
       <div class="section" style="margin:0pt"> 
        <div class="titlepage" style="margin:0pt"> 
         <div style="margin:0pt"> 
          <div style="margin:0pt"> 
           <h3 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:20px"> 19.9.8 Customizing WebDataBinder initialization</h3> 
          </div> 
         </div> 
        </div> 
        <p style="margin-top:0px; margin-bottom:15px">To customize request parameter binding with PropertyEditors, etc. via Spring’s <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebDataBinder</code>, you can either use <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@InitBinder</code>-annotated methods within your controller or externalize your configuration by providing a custom <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebBindingInitializer</code>.</p> 
        <div class="section" style="margin:0pt"> 
         <div class="titlepage" style="margin:0pt"> 
          <div style="margin:0pt"> 
           <div style="margin:0pt"> 
            <h4 class="title" style="color:rgb(0,0,0); margin:30px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:18px"> Customizing data binding with @InitBinder</h4> 
           </div> 
          </div> 
         </div> 
         <p style="margin-top:0px; margin-bottom:15px">Annotating controller methods with <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@InitBinder</code> allows you to configure web data binding directly within your controller class. <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@InitBinder</code> identifies methods which initialize the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebDataBinder</code> which will be used for populating command and form object arguments of annotated handler methods.</p> 
         <p style="margin-top:15px; margin-bottom:15px">Such init-binder methods support all arguments that <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@RequestMapping</code> supports, except for command/form objects and corresponding validation result objects. Init-binder methods must not have a return value. Thus, they are usually declared as <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">void</code>. Typical arguments include <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebDataBinder</code> in combination with <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebRequest</code> or<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.util.Locale</code>, allowing code to register context-specific editors.</p> 
         <p style="margin-top:15px; margin-bottom:15px">The following example demonstrates the use of <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">@InitBinder</code> for configuring a <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">CustomDateEditor</code> for all <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">java.util.Date</code> form properties.</p> 
         <pre><code liberation="" mono=""><em><span class="hl-annotation" style="color:gray">@Controller</span></em>
<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span> MyFormController {

    <em><span class="hl-annotation" style="color:gray">@InitBinder</span></em>
    <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">public</span> <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">void</span> initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> SimpleDateFormat(<span class="hl-string" style="color:rgb(42,0,255)">"yyyy-MM-dd"</span>);
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.<span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">class</span>, <span class="hl-keyword" style="color:rgb(127,0,85); font-weight:bold">new</span> CustomDateEditor(dateFormat, false));
    }

    <span class="hl-comment" style="color:rgb(63,95,95); font-style:italic">// ...</span>

}</code></pre> 
        </div> 
        <div class="section" style="margin:0pt"> 
         <div class="titlepage" style="margin:0pt"> 
          <div style="margin:0pt"> 
           <div style="margin:0pt"> 
            <h4 class="title" style="color:rgb(0,0,0); margin:30px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:18px"> Configuring a custom WebBindingInitializer</h4> 
           </div> 
          </div> 
         </div> 
         <p style="margin-top:0px; margin-bottom:15px">To externalize data binding initialization, you can provide a custom implementation of the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">WebBindingInitializer</code> interface, which you then enable by supplying a custom bean configuration for an <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">AnnotationMethodHandlerAdapter</code>, thus overriding the default configuration.</p> 
        </div> 
       </div> 
      </div> 
      <div class="section" style="margin:0pt; color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:14px"> 
       <div class="titlepage" style="margin:0pt"> 
        <div style="margin:0pt"> 
         <div style="margin:0pt"> 
          <h2 class="title" style="color:rgb(0,0,0); margin:40px 0px 10px -1em; padding:0px 0px 0px 1em; font-size:24px; clear:both"> 19.10 Portlet application deployment</h2> 
         </div> 
        </div> 
       </div> 
       <p style="margin-top:0px; margin-bottom:15px">The process of deploying a Spring Portlet MVC application is no different than deploying any JSR-168 Portlet application. However, this area is confusing enough in general that it is worth talking about here briefly.</p> 
       <p style="margin-top:15px; margin-bottom:15px">Generally, the portal/portlet container runs in one webapp in your servlet container and your portlets run in another webapp in your servlet container. In order for the portlet container webapp to make calls into your portlet webapp it must make cross-context calls to a well-known servlet that provides access to the portlet services defined in your <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">portlet.xml</code> file.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The JSR-168 specification does not specify exactly how this should happen, so each portlet container has its own mechanism for this, which usually involves some kind of "deployment process" that makes changes to the portlet webapp itself and then registers the portlets within the portlet container.</p> 
       <p style="margin-top:15px; margin-bottom:15px">At a minimum, the <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">web.xml</code> file in your portlet webapp is modified to inject the well-known servlet that the portlet container will call. In some cases a single servlet will service all portlets in the webapp, in other cases there will be an instance of the servlet for each portlet.</p> 
       <p style="margin-top:15px; margin-bottom:15px">Some portlet containers will also inject libraries and/or configuration files into the webapp as well. The portlet container must also make its implementation of the Portlet JSP Tag Library available to your webapp.</p> 
       <p style="margin-top:15px; margin-bottom:15px">The bottom line is that it is important to understand the deployment needs of your target portal and make sure they are met (usually by following the automated deployment process it provides). Be sure to carefully review the documentation from your portal for this process.</p> 
       <p style="margin-top:15px; margin-bottom:15px">Once you have deployed your portlet, review the resulting <code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">web.xml</code> file for sanity. Some older portals have been known to corrupt the definition of the<code liberation="" mono="" color:rgb="" background-color:rgb="" border:1px="" solid="" rgb="" padding:1px="" white-space:nowrap="">ViewRendererServlet</code>, thus breaking the rendering of your portlets.</p> 
      </div> 
      <span style="color:rgb(51,51,51); font-family:Helvetica,Arial,Freesans,Clean,sans-serif; font-size:24px">    :</span> http://spring.cndocs.tk/index.html 
      <br/> 
     </div> 
    </div> 
   </div> 
  </div> 
 </div> 
</div>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기