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.

3 comments:

srjwebsolutions said...

We are leading responsive website designing and development company in Noida.
We are offering mobile friendly responsive website designing, website development, e-commerce website, seo service and sem services in Noida.

Responsive Website Designing Company in Noida
Website Designing Company in Noida
SEO Services in Noida
SMO Services in Noida

Vikas Chaudhary said...

Battery Mantra is Authorized exide car battery dealer in Noida and Greater Noida. We are providing our service in Indirapuram, Delhi, Ashok Nagar.

Exide Battery Dealer in Noida
Battery Dealer in Noida
Authorized Battery Dealer in Noida
Car Battery Dealer in Noida
Car Battery Dealer
Exide Battery Dealer

EG MEDI said...

Egmedi.com is online medical store pharmacy in laxmi nagar Delhi. You can Order prescription/OTC medicines online.
Cash on Delivery available. Free Home Delivery


Online Pharmacy in Delhi
Buy Online medicine in Delhi
Online Pharmacy in laxmi nagar
Buy Online medicine in laxmi nagar
Onine Medical Store in Delhi
Online Medical store in laxmi nagar
Online medicine store in delhi
online medicine store in laxmi nagar
Purchase Medicine Online
Online Pharmacy India
Online Medical Store