开发者

RequestMapping with Spring Portlet MVC 3

I have a portal page that has two windows on it. Each window represents an instance of an annotated Spring Portlet MVC portlet.

In both portlets (Controllers) I have a "default" @RequestMapping; is it possible for me to distinguish in the @RequestMapping annotation which Render request should run? For some reason the same mapping (开发者_如何转开发only one controller) is running for both requests.


I will show my approach for this, as I was needing to handle the requests to the main view with one controller, and the requests to a pop-up being part of the portlet with another controller using Spring MVC 3.0.5.

The main controller will be called if there is not a parameter called view in the request, and the pop-up controller if the view parameter has the value 'popup'. Here are the spring configuration of the portlet-app and the annotations set on the controllers:

Spring configuration: app-portlet.xml

Important! Pay attention that the package is org.springframework.web.portlet.mvc.annotation, and don't use <mvc:annotation-driven /> instead of the handler mappings, as it will register the servlet handler mappings.

<!-- Scan the desired package for annotations -->
<context:component-scan 
 base-package="com.company.project.myportlet" />

<!-- Handler mappings for annotation based controllers -->
<bean         
 class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean      
 class="org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

Main Controller

package com.company.project.myportlet;
@Controller
@RequestMapping(value="VIEW",params="!view")
public class MainPageController {
    //...
}

Pop-up Controller

package com.company.project.myportlet;
@Controller
@RequestMapping(value="VIEW",params="view=popup")
public class PopupController {
    //...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜