Supporting custom portlet mode in Spring Portlet MVC Framework

In the Supporting Multiple modes with Spring Portlet MVC Framework, entry i built a sample portlet to demonstrate how you can support more than one portlet mode in Spring Portlet MVC Framework portlet. I changed that sample to see what it will take to add support for custom portlet mode in Spring Portlet MVC Framework portlet.

First i had to add a new Controller class that will get called whenever this portlet gets invoked int the config mode, like this

package com.webspherenotes.mvc.spring.action;

import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.mvc.AbstractController;

public class ConfigController extends AbstractController{

public ModelAndView handleRenderRequest(RenderRequest request,
RenderResponse response) throws Exception {
System.out.println("Entering ConfigController.handleRenderRequest()");
ModelAndView modelAndView = new ModelAndView("config");
System.out.println("Exiting ConfigController.handleRenderRequest()");
return modelAndView;
}

}


Then i had to change the MultipleModesPortlet-portlet.xml, spring configuration file for the portlet like this


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="viewController"
class="com.webspherenotes.mvc.spring.action.ViewController" />

<bean id="editController"
class="com.webspherenotes.mvc.spring.action.EditController" />

<bean id="helpController"
class="com.webspherenotes.mvc.spring.action.HelpController" />

<bean id="configController"
class="com.webspherenotes.mvc.spring.action.ConfigController" />

<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1" />
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="viewController" />
</entry>
<entry key="edit">
<ref bean="editController" />
</entry>
<entry key="help">
<ref bean="helpController" />
</entry>
<entry key="config">
<ref bean="configController" />
</entry>

</map>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>


So i had to map the config mode to configModeController bean in the portletModeMap.

No comments: