El Guapo
El Guapo

Reputation: 5781

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.

Upvotes: 0

Views: 3682

Answers (1)

AdrianRM
AdrianRM

Reputation: 2761

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 {
    //...
}

Upvotes: 1

Related Questions