Showing posts with label springportletmvc. Show all posts
Showing posts with label springportletmvc. Show all posts

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.

Handling portlet events in Spring Portlet MVC Framework

The Spring Portlet MVC Framework has concept of EventAwareController that can be implemented by your Controller class to indicate that it can handle events.

I built two sample portlets one is SpringSourcePortlet and other is SpringTargetPortlet to demonstrate how you can send and receive events in Spring Portlet MVC framework application. You can download the sample code from here

  1. Contact

  2. SpringSourcePortlet

  3. SpringTargetPortlet



I followed these steps to create my sample application

  • First create Contact.java in separate Java project like this

    package com.webspherenotes.portlet.events;

    import java.io.Serializable;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement
    public class Contact implements Serializable{
    private static final long serialVersionUID = -1637774642655976822L;
    private String firstName;
    private String lastName;
    private String email;
    public Contact(){
    }
    public Contact(String firstName, String lastName, String email) {
    super();
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
    }
    public String getFirstName() {
    return firstName;
    }
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    }
    public String getLastName() {
    return lastName;
    }
    public void setLastName(String lastName) {
    this.lastName = lastName;
    }
    public String getEmail() {
    return email;
    }
    public void setEmail(String email) {
    this.email = email;
    }
    }


    The Contact.java implements Serializable object and has @XmlRootElement annotation to indicate that this object can be passed either locally or using WSRP

  • Create SpringSourcePortlet using Spring Portlet MVC Framework. In that create ViewModeController.java like this

    package com.webspherenotes.portlet.spring;

    import javax.portlet.ActionRequest;
    import javax.portlet.ActionResponse;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;

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

    import com.webspherenotes.portlet.events.Contact;

    public class ViewModeController extends AbstractController{

    public void handleActionRequest(ActionRequest request,
    ActionResponse response) throws Exception {
    System.out.println("Entering ViewModeController.handleActionRequest");
    String fName = request.getParameter("fName");
    String lName = request.getParameter("lName");
    String email = request.getParameter("email");
    Contact contact = new Contact(fName, lName, email);
    response.setEvent("hello", contact);
    request.getPortletSession().setAttribute("contact", contact);
    System.out.println("Exiting ViewModeController.handleActionRequest");
    }

    public ModelAndView handleRenderRequest(RenderRequest request,
    RenderResponse response) throws Exception {
    System.out.println("Entering ViewModeController.handleRenderRequest");
    response.setContentType("text/html");
    ModelAndView modelAndView = new ModelAndView("source");
    if (request.getPortletSession().getAttribute("contact") != null) {
    modelAndView.addObject("contact", request.getPortletSession()
    .getAttribute("contact"));
    }
    System.out.println("Exiting ViewModeController.handleRenderRequest");
    return modelAndView;
    }
    }


    The handleRenderRequest() method of the ViewModeController, forwards control to source.jsp for generating markup. The source.jsp displays a form to user.

    The handleActionRequest() method of ViewModeController gets called when user enters values on Contact form and clicks submit. Inside this method i am reading values submitted by user, then creating a Contact object and passing it as value of the event.

  • This is how my SpringSourcePortlet-portlet.xml file looks like

    <?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.portlet.spring.ViewModeController" />
    <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>
    </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>

    The SpringSourcePortlet has only one controller class which is ViewModeController and it is set as a default VIEW mode controller

  • Next create SpringTargetPortlet and inside that create ViewModeController.java like this

    package com.webspherenotes.portlet.spring;

    import javax.portlet.Event;
    import javax.portlet.EventRequest;
    import javax.portlet.EventResponse;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;

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

    import com.webspherenotes.portlet.events.Contact;

    public class ViewModeController extends AbstractController implements EventAwareController{
    public ModelAndView handleRenderRequest(RenderRequest request,
    RenderResponse response) throws Exception {
    System.out.println("Entering ViewModeController.handleRenderRequest");
    response.setContentType("text/html");
    Contact contact = (Contact) request.getPortletSession().getAttribute(
    "contact");
    if (contact != null) {
    response.getWriter().println(
    "First Name " + contact.getFirstName() + "
    Last Name "
    + contact.getLastName() + "
    Email "
    + contact.getEmail());
    } else {
    response.getWriter().println("Contact not found in session ");
    }
    System.out.println("Entering ViewModeController.handleRenderRequest");
    return new ModelAndView();
    }


    public void handleEventRequest(EventRequest request, EventResponse response)
    throws Exception {
    System.out.println("Entering ViewModeController.handleEventRequest");
    Event event = request.getEvent();
    System.out.println("Event Name " + event.getName());
    Contact contact = (Contact) event.getValue();
    System.out.println("Contact First Name " + contact.getFirstName());
    System.out.println("Contact Last Name " + contact.getLastName());
    System.out.println("Contact Email " + contact.getEmail());
    request.getPortletSession().setAttribute("contact", contact);
    System.out.println("Exiting ViewModeController.handleEventRequest");
    }

    }

    The ViewModeController.java implements EventAwareController interface to indicate that it can be used for handling events. It has a handleEventRequest method that will get called when it receives event. Inside this method we get access to EventRequest and EventResponse object. I am reading Contact object which was passed as event payload and setting it as attribute in the PortletSession.

    The handleRenderRequest() method reads the value of Contact object from the PortletSession and then displays those values to the user

  • This is how the SpringTargetPortlet-portlet.xml file of SpringTargetPortlet looks like

    <?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.portlet.spring.ViewModeController" />
    <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>
    </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>

    The SpringTargetPortlet has only one ViewModeController and it is set as default controller for the VIEW mode.

Handling multiple resource requests in Spring Portlet

The Handling Resource request in Spring MVC Portlet, demonstrates how to make a resource request to the Spring Portlet MVC Framework portlet, that portlet has only one Controller class, but in reality you will want to have more than one Controller classes for handling different resource request

I did create a MultipleResourceRequests portlet to demonstrate how you can have different Controller classes for handling different resource requests inside your Spring Portlet. My sample portlet has 4 Controller first is ViewModeController which is used for handling render request for VIEW mode and three different controllers Resource1Controller, Resource2Controller and Resource3Controller for handling resource requests. The Spring Portlet MVC Framework makes use value of action parameter to route request to different Controller, we will use different values of action parameters for routing resource requests to one of our ResourceController

This is how my ViewModeController.java looks like

package com.webspherenotes.portlet;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

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

public class ViewModeController extends AbstractController{

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

}


The ViewModeController has only handleRenderRequest, which gets invoked when the portlet gets render request and inside this method i am forwarding control to view.jsp for generating markup. This is how my view.jsp looks like


<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects />

<portlet:resourceURL var="resource1Url" >
<portlet:param name="action" value="resource1" />
</portlet:resourceURL>
<portlet:resourceURL var="resource2Url" >
<portlet:param name="action" value="resource2" />
</portlet:resourceURL>
<portlet:resourceURL var="resource3Url" >
<portlet:param name="action" value="resource3" />
</portlet:resourceURL>

<script type="text/javascript">
dojo.addOnLoad( function () { dojo.parser.parse( "<portlet:namespace/>portletWidgetContainer" ); } );
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
</script>

<div id="<portlet:namespace/>portletWidgetContainer">
<button dojoType="dijit.form.Button" id="btn1">Resource1
<script type="dojo/method" event="onClick">
dojo.xhrGet({
url: "<%=resource1Url%>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button><br/>
<button dojoType="dijit.form.Button" id="btn2">Resource2
<script type="dojo/method" event="onClick">
dojo.xhrGet({
url: "<%=resource2Url%>",
load: function(data, ioargs){

dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button><br/>
<button dojoType="dijit.form.Button" id="btn3">Resource3
<script type="dojo/method" event="onClick">
dojo.xhrGet({
url: "<%=resource3Url%>",
load: function(data, ioargs){
dojo.byId("resourceResponse").innerHTML = data;
},
error: function(error,ioargs){
alert(error);
}
});
</script>
</button><br/>
<div id="resourceResponse" />
</div>


The view.jsp is using Dojo and Dijit to display three different buttons. When you click on this button it is making a resourceURL call and while making resourceURL call it is setting value of action parameter as either resource1, resource2 or resource3

One the Spring Portlet gets control it will look at value of action parameter to figure out the Controller that should be used for handling this request. It does by finding the entry for value of action parameter in portletModeParameterMap

<?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.portlet.ViewModeController" />
<bean id="resource1Controller" class="com.webspherenotes.portlet.Resource1Controller" />
<bean id="resource2Controller" class="com.webspherenotes.portlet.Resource2Controller" />
<bean id="resource3Controller" class="com.webspherenotes.portlet.Resource3Controller" />
<bean id="parameterMappingInterceptor"
class="org.springframework.web.portlet.handler.ParameterMappingInterceptor" />
<bean id="portletModeParameterHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
<property name="order" value="1" />
<property name="interceptors">
<list>
<ref bean="parameterMappingInterceptor" />
</list>
</property>
<property name="portletModeParameterMap">
<map>
<entry key="view">
<map>
<entry key="view">
<ref bean="viewController" />
</entry>
<entry key="resource1">
<ref bean="resource1Controller" />
</entry>
<entry key="resource2">
<ref bean="resource2Controller" />
</entry>
<entry key="resource3">
<ref bean="resource3Controller" />
</entry>

</map>

</entry>
</map>
</property>
</bean>
<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="2" />
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="viewController" />
</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>

THe sample portlet configuration set ViewModeController as default controller for the portlet and then maps Resource1Controller to resource1 and so on. This is how my Resource1Controller looks like


package com.webspherenotes.portlet;

import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

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

public class Resource1Controller extends AbstractController implements ResourceAwareController{

public ModelAndView handleResourceRequest(ResourceRequest arg0,
ResourceResponse arg1) throws Exception {
System.out.println("Entering Resource1Controller.handleResourceRequest()");
ModelAndView modelAndView = new ModelAndView("resource1");
System.out.println("Exiting Resource1Controller.handleResourceRequest()");
return modelAndView;
}
}


The Resource1Controller implements only handleResourceRequest method, that means it can only handle resource request. Inside the handleResourceRequest method it is forwarding control to resource1.jsp for generating markup

Handling Resource request in Spring MVC Portlet

Starting from Version 3.0.1, Spring Framework support some of the new features introduced in the Portlet Specification 2.0 (JSR 286). One of the new features in the Portlet Specification 2.0, is ability to make resource request.

The Spring Portlet MVC Framework 3.0.* has concept of ResourceAwareController interface that you can implement in your Controller class to indicate that your Controller can be used for handling resource request. You can download the sample code from here

I built this simple ServeResource portlet to demonstrate how to handle resource request in Spring Portlet MVC Framework. The sample portlet supports only VIEW mode and it has only one ViewController class for handling all the requests


package com.webspherenotes.mvc.spring.action;

import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

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

public class ViewController extends AbstractController implements ResourceAwareController{
protected ModelAndView handleRenderRequestl(RenderRequest request,
RenderResponse response) throws Exception {
System.out.println("Entering ViewController.handleRenderRequest()");
ModelAndView modelAndView = new ModelAndView("hello");
System.out.println("Exiting ViewController.handleRenderRequest()");
return modelAndView;
}
public ModelAndView handleResourceRequest(ResourceRequest arg0,
ResourceResponse arg1) throws Exception {
System.out.println("Entering ViewController.handleResourceRequest()");
ModelAndView modelAndView = new ModelAndView("helloresource");
System.out.println("Exiting ViewController.handleResourceRequest()");
return modelAndView;
}
}


The ViewController implements ResourceAwareController interface and as a result it has implement
handleResourceRequest() method which gets called whenever a resource call is made to the portlet.

  1. handleRenderRequest: This method will get called to handle render request for the portlet in the VIEW mode. In my sample portlet i am working control to hello.jsp for generating markup

  2. handleResourceRequest: This method will get called to handle resource request for the portlet. Inside this method you will get access to ResourceRequest and ResourceResponse object and after processing the request, you can return object of ModelAndView type which will be used for forwarding control to JSP. In my sample portlet i am forwarding control to helloresource.jsp for generating markup for resource request



This is how my hello.jsp, looks like. This jsp has one "Resource Call" button and when you click on that button, it makes use of JavaScript to make a HTTP Get call to portlet:resourceURL, and once the response is returned it is displaying that response as alert on the page


<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<h1>Hello from doView</h1>
<script type="text/javascript">
function createXMLHttpRequestObject() {
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
} catch (e) {
}
}
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}
var xmlHttp = createXMLHttpRequestObject();
function makeResourceCall(){
if (xmlHttp){
try{
xmlHttp.open("GET", "<portlet:resourceURL/>", true);
xmlHttp.onreadystatechange = handleRequestStateChange;
xmlHttp.send(null);
}catch (e){
alert("Can't connect to server:\n" + e.toString());
}
}
}
function handleRequestStateChange(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
alert(xmlHttp.responseText);

}
}
}
</script>
<input type="button" onclick="JavaScript:makeResourceCall()" value="Resource Call" />


The helloresource.jsp is pretty simple, it is just returning following text

This is response of ServeResourcePortlet.serveResource() call

Handling Multiple Actions in Spring Portlet MVC Framework

In the Handling actions in Spring Portlet MVC Framework entry, we looked at the sample of how to handle action request inside your portlet. But that portlet had only one controller. In most of the real world scenarios you will want to break your portlet into multiple Controllers where a different Controller class will be responsible for handling different actions.

In this entry we will look at sample of how you can use multiple Controllers in one Mode and how to forward control to these controllers based on URL parameter. The MultipleActionsPortlet will have 4 Controllers for VIEW mode. ViewModeController will be the default Controller, which will get control when you call portlet for first time, It will have Action1Controller, Action2Controller and Action3Controller, depending on value of the action parameter. Each of these Controllers simply forward control to different JSPs. You can download sample code from here.

This is how the ViewModeController.java looks like

package com.webspherenotes.portlet;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

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

public class ViewModeController extends AbstractController{

public void handleActionRequest(ActionRequest request,
ActionResponse response) throws Exception {
System.out.println("Entering ViewModeController.handleActionRequest()");
System.out.println("Exiting ViewModeController.handleActionRequest()");
}

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


}


The ViewModeController is very simple, only thing that it does is forward control to view.jsp for generating markup. This is how the view.jsp looks like

<%@page language="java" contentType="text/html; %>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<portlet:defineObjects />

<h1>view.jsp</h1>
<table>
<tr>
<td>
<a href='<portlet:actionURL>
<portlet:param name="action" value="action1" />
</portlet:actionURL>'>Action 1</a>
</td>
</tr>
<tr>
<td>
<a href='<portlet:actionURL>
<portlet:param name="action" value="action2" />
</portlet:actionURL>'>Action 2</a>
</td>
</tr>
<tr>
<td>
<a href='<portlet:actionURL>
<portlet:param name="action" value="action3" />
</portlet:actionURL>'>Action 3</a>
</td>
</tr>
</table>


The view.jsp is generating 3 different actionURL's with different values for action parameter. The Spring Portlet MVC framework reads the value of action parameter to decide which Controller class will get control for handling the URL.

I did create three similar ActionControllers for handling other 3 actions, This is how the Action1Controller looks like

package com.webspherenotes.portlet;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

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

public class Action1Controller extends AbstractController{

public void handleActionRequest(ActionRequest request,
ActionResponse response) throws Exception {
System.out.println("Entering Action1Controller.handleActionRequest()");
System.out.println("Exiting Action1Controller.handleActionRequest()");
}

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

}


The handleActionRequest of Action1Controller does not do anything only thing that it does in handleRenderRequest is to forward control to action1.jsp for rendering markup.

The most important part in handling multiple actions is the Spring Configuration, this is how my Spring configuration looks like

<?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.portlet.ViewModeController" />
<bean id="action1Controller"
class="com.webspherenotes.portlet.Action1Controller" />
<bean id="action2Controller"
class="com.webspherenotes.portlet.Action2Controller" />
<bean id="action3Controller"
class="com.webspherenotes.portlet.Action3Controller" />


<bean id="parameterMappingInterceptor"
class="org.springframework.web.portlet.handler.ParameterMappingInterceptor" />
<bean id="portletModeParameterHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
<property name="order" value="1" />
<property name="interceptors">
<list>
<ref bean="parameterMappingInterceptor" />
</list>
</property>
<property name="portletModeParameterMap">
<map>
<entry key="view">
<map>
<entry key="view">
<ref bean="viewController" />
</entry>
<entry key="action1">
<ref bean="action1Controller" />
</entry>
<entry key="action2">
<ref bean="action2Controller" />
</entry>
<entry key="action3">
<ref bean="action3Controller" />
</entry>

</map>
</entry>
</map>
</property>
</bean>


<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="2" />
<property name="portletModeMap">
<map>
<entry key="view">
<ref bean="viewController" />
</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>




As you can see, we have defined two new bean definitions in the SpringContactManagPortlet-portlet.xml file.

  1. parameterMappingInterceptor. The parameterMappingInterceptor is used to forward the value of the action request parameter from ActionRequest to RenderRequest, so that Spring Portlet MVC Framework uses the same controller for handling both the action request and the render request. If you dont use this interceptor you will have to manually copy value of action parameter in handleActionRequest as render parameter

  2. portletModeParameterHandlerMapping. portletModeParameterHandlerMapping is an advanced implementation of HandlerMapping that uses the portlet mode as well as the value of the action request parameter to resolve the handler for the request. In the sample code, we have more than one handler in View mode so we use portletModeParameterHandlerMapping. The portletModeParameterHandlerMapping bean has the portletModeParameterMap property, which is a map of all the portlet modes that your portlet supports. This map takes key value pairs with the name of the portlet mode as the key. Value is another map that takes the value of the action request parameter as the key and the reference to the controller that handles its request as its value.



We also have the old org.springframework.web.portlet.handler.PortletModeHandlerMapping bean which is mapping ViewModeController as default Controller for the VIEW mode, its required for handling the default request or the request which does not have action parameter. It has property order equal to 2 to demonstrate that this HandleMapping bean should be used only if the portletModeParameterHandlerMapping is not able to map request to Controller

Spring Portlet MVC Framework Information

In 2007 i wrote following 3 part series on how to use Spring Portlet MVC Framework for IBM's developerworks. That series was based on Spring Framework 2.0.8


  1. Developing a Spring Portlet MVC Framework application for use inside IBM WebSphere Portal: Introduction to Spring Portlet MVC Framework

  2. Developing a Spring Portlet MVC Framework application for use inside IBM WebSphere Portal: Handling form submissions

  3. Developing a Spring Portlet MVC Framework application for use inside IBM WebSphere Portal: Advanced Spring Portlet MVC Framework



Starting from Version 3.0.1, Spring Portlet MVC Framework started supporting Portlet Specification 2.0, so i did spent some time playing with it and this is list of information on my blog about the Spring Portlet MVC Framework 3.0.1

Handling actions in Spring Portlet MVC Framework

In the HelloWorld Spring Portlet MVC Framework 3.0.1 entry, i covered the steps required to create simple HelloWorld portlet, that will forward control to a JSP in the view mode, but that portlet does not support action requests. I built a HelloSpring31ActionPortlet to demonstrate how to handle action request in the portlet.

The HelloSpring31ActionPortlet portlet supports two modes VIEW and EDIT. It displays a form in the EDIT mode where user can enter value for userName and when user submits the form it will save that value in the userName preference. Then in the VIEW mode it reads that value and shows a customized greeting message to the user.

I had to follow these steps to build this application


  • First i built this EditController.java, which will be responsible for handling requests when the portlet is invoked in the EDIT mode

    package com.webspherenotes.mvc.spring.action;

    import javax.portlet.ActionRequest;
    import javax.portlet.ActionResponse;
    import javax.portlet.PortletMode;
    import javax.portlet.PortletPreferences;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;
    import org.springframework.web.portlet.ModelAndView;
    import org.springframework.web.portlet.mvc.AbstractController;

    public class EditController extends AbstractController{
    public void handleActionRequest(ActionRequest request,
    ActionResponse response) throws Exception {
    System.out.println("Entering EditController.handleActionRequest");
    String userName = request.getParameter("userName");
    PortletPreferences preferences = request.getPreferences();
    preferences.setValue("userName", userName);
    preferences.store();
    response.setPortletMode(PortletMode.VIEW);
    System.out.println("Exiting EditController.handleActionRequest");
    }
    public ModelAndView handleRenderRequest(RenderRequest request,
    RenderResponse response) throws Exception {
    System.out.println("Entering EditController.handleRenderRequest");
    ModelAndView modelAndView = new ModelAndView("edit");
    System.out.println("Exiting EditController.handleRenderRequest");
    return modelAndView;
    }
    }


    The EditController has two methods

    1. handleActionRequest: This method gets called whenever you try to access the actionURL pointing to the Edit mode of the portlet. Inside this method you get access to ActionRequest and ActionResponse object, i am using this opportunity to read the value of userName parameter submitted by user and setting it in preference

    2. handleRenderRequest: This method gets called to get markup for edit mode of the portlet. I am using it for forwarding control to edit.jsp




  • This how the edit.jsp page looks like

    <%@page language="java" contentType="text/html; %>
    <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <portlet:defineObjects />
    <form method="POST" action="<portlet:actionURL/>">
    <table>
    <tr>
    <td>User Name</td>
    <td><input type="text" name="userName" /></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" /></td>
    </tr>
    </table>
    </form>

    As you can see this JSP is similar to any other portlet JSP, all that it is doing is submitting a form to actionURL


  • This is how the ViewController.jsp for my portlet looks like

    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 ViewController extends AbstractController{
    public ModelAndView handleRenderRequest(RenderRequest request,
    RenderResponse response) throws Exception {
    System.out.println("Entering ViewController.handleRenderRequest()");
    ModelAndView modelAndView = new ModelAndView("view");
    modelAndView.addObject("userName",
    request.getPreferences().getValue("userName", "User Name is not set"));
    System.out.println("Exiting ViewController.handleRenderRequest()");
    return modelAndView;
    }
    }


    The ViewController class has only handleRenderRequest method and it does not support actionURl being called for view mode. In the handleRenderRequest i am reading value of the userName preference setting it in the request object by adding it in the ModelAndView and then forwarding control to view.jsp


  • This is how the view.jsp looks like

    <%@page language="java" contentType="text/html; %>
    <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <portlet:defineObjects />
    <h1>Hello <%=renderRequest.getAttribute("userName") %></h1>

    Here i am reading the value of userName attribute from request and then using it build customized greeting for user


  • This is how the spring configuration for my portlet looks like, as you can see i have two beans for two different modes and then portletModeHandlerMapping is used for mapping the bean name to the mode

    <?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="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>
    </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>


Supporting Multiple modes with Spring Portlet MVC Framework

In the HelloWorld Spring Portlet MVC Framework 3.0.1 entry i did build a simple HelloWorld Spring portlet which supports only VIEW mode.

Today i built a MultipleModesPortlet to demonstrate how you can support more than one mode using Spring MVC Framework. You can download the sample code from here

The MutlipleModesPortlet, support three modes VIEW, EDIT and HELP, It has one controller class for every mode. Ex ViewController class will handle every request for VIEW mode, the EditController class will handle every request for EDIT mode and HelpController class will handle every request for help mode. Only thing that Controller does is forward control to a JSP for rendering markup. The ViewController forwards control to view.jsp and similarly the other controller forward control to corresponding JSP.

This is how my ViewController.java looks like

public class ViewController extends AbstractController{
protected ModelAndView handleRenderRequestInternal(RenderRequest request,
RenderResponse response) throws Exception {
System.out.println("Entering ViewController.handleRenderRequest()");
ModelAndView modelAndView = new ModelAndView("view");
System.out.println("Exiting ViewController.handleRenderRequest()");
return modelAndView;
}
}


As you can see the ViewController class overrides handleRenderRequestInternal() method which gets call every time user tries to access the portlet in VIEW mode. Inside the handleRenderRequestInternal() method i am creating and returning ModelAndView("view") object. Which is equivalent to forwarding control to JSP for generating markup.

This is how my view.jsp looks like

<%@page language="java" contentType="text/html; %>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<h1>Hello from view.jsp</h1>

As you can see this JSP is generating static text.

Now the more important part is how to configure Spring Portlet MVC framework so that different controllers get called for different modes and the answer is that configuration goes in MultipleModes-portlet.xml 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="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>
</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>


As you can see first i have created three bean definitions one for each Controller, this is the Controller class for com.webspherenotes.mvc.spring.action.EditController

Then the important part is portletModeHandlerMapping which has portletModeMap map that is used for mapping a Controller class to the mode. I am mapping view mode to viewController and edit mode to editController,..

HelloWorld Spring Portlet MVC Framework 3.0.1

Spring Portlet MVC Framework 3.0.1 has support for developing Portlet Specification 2.0 compliant portlets.

I want to learn about how to use Spring for developing Portlet Specification 2.0 compliant so i built this HelloWorld portlet. This portlet is very simple, it has one Controller for handling all View mode related requests ant that controller sets a string in request object and forwards control to JSP for displaying markup, but i am using it as starting point. You can download the sample code from here and follow these steps to create your own portlet


  1. First download the Spring Framework 3.0.2 from the Spring Framework Site

  2. Create a portlet and copy following jars in the WEB-INF/lib folder of your portlet, you can download the sample portlet from here and copy these jars from it

    • aopalliance-1.0.jar

    • commons-logging-1.1.1.jar

    • spring-aop-3.0.2.jar
    • spring-asm-3.0.2.RELEASE.jar

    • spring-beans-3.0.2.RELEASE.jar

    • spring-context-3.0.2.RELEASE.jar

    • spring-context-support-3.0.2.RELEASE.jar

    • spring-core-3.0.2.RELEASE.jar

    • spring-expression-3.0.2.RELEASE.jar

    • spring-web-3.0.2.RELEASE.jar

    • spring-webmvc-3.0.2.RELEASE.jar

    • spring-webmvc-portlet-3.0.2.RELEASE.jar


    If your using the Apache Maven as build tool then you can add following dependencies for your project and it will take care of downloading and packaging appropriate jars

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc-portlet</artifactId>
    <version>${spring.version}</version>
    <scope>compile</scope>
    </dependency>
    </dependencies>



  3. Next step is to add org.springframework.web.portlet.DispatcherPortlet portlet in your portlet.xml like this. The DispatcherPorltet is Controller portlet and responsible for handling every portlet request

    <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
    version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
    http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
    <portlet>
    <portlet-name>HelloSpring31Portlet</portlet-name>
    <display-name>Hello Spring 31 Portlet</display-name>
    <portlet-class>org.springframework.web.portlet.DispatcherPortlet
    </portlet-class>

    <expiration-cache>0</expiration-cache>
    <supports>
    <mime-type>text/html</mime-type>
    <portlet-mode>view</portlet-mode>
    </supports>
    <portlet-info>
    <title>Hello Spring 31 Portlet</title>
    <short-title>Hello Spring 31 Portlet</short-title>
    <keywords>Hello Spring 31 Portlet</keywords>
    </portlet-info>
    </portlet>
    </portlet-app>


  4. Now change your web.xml and add org.springframework.web.servlet.ViewRendererServlet to it like this, this step would make sure that you can use the Spring View layer in your portlet

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>HelloSpring31Portlet</display-name>
    <servlet>
    <servlet-name>ViewRendererServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>ViewRendererServlet</servlet-name>
    <url-pattern>/WEB-INF/servlet/view</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


  5. The next step is to create a Spring configuration file in the WEB-INF directory, the name of the file should be HelloSpring31Portlet-portlet.xml, basic idea is name of the configuration file should <portletname>-portlet.xml, where portletname is defined in portlet.xml,

    <?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="helloSpring31Action"
    class="com.webspherenotes.mvc.spring.action.HelloSpring31Action" />
    <bean id="portletModeHandlerMapping"
    class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
    <property name="order" value="1" />
    <property name="portletModeMap">
    <map>
    <entry key="view">
    <ref bean="helloSpring31Action" />
    </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>

    This file has following 3 bean definitions

    • com.webspherenotes.mvc.spring.action.HelloSpring31Action This is Controller or Action class that i am going to develop next

    • org.springframework.web.portlet.handler.PortletModeHandlerMapping This bean is used for mapping controller class to the mode, It allows you to map only one Controller or Action class for every mode, in our sample code i am mapping helloSpring31Action to the VIEW mode, that means whenever this portlet gets called in VIEW mode it will pass control to helloSpring31Action for generating response

    • org.springframework.web.servlet.view.InternalResourceViewResolver: This bean is used for resolving a resource, In our case i am saying that i am going to use JSPs for view i.e. genearting markup and all my JSPs are placed inside WEB-INF/jsp folder, so i am setting value of prefix attribute to WEB-INF/jsp the value of suffix attribute is .jsp that means the extension for all my JSP file. Now inside my controller class when i forward control to ModelAndView("hello"), it will take that value and forward control to /WEB-INF/jsp/hello.jsp for generating markup



  6. Next create applicationContext.xml file in your WEB-INF folder, it will be valid spring configuration file like this but wont have any bean definition. Every Spring Web MVC application will look for it and will fail if its not able to find this file. You can use it to define application level beans

    <?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>
    </beans>


  7. Next create HelloSpring31Action class 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 HelloSpring31Action extends AbstractController{
    protected ModelAndView handleRenderRequestInternal(RenderRequest request,
    RenderResponse response) throws Exception {
    System.out.println("Entering HelloSpring31Action.handleRenderRequestInternal()");
    ModelAndView modelAndView = new ModelAndView("hello");
    modelAndView.addObject("userName", "Sunil");

    System.out.println("Exiting HelloSpring31Action.handleRenderRequestInternal()");
    return modelAndView;
    }
    }

    As you can see the HelloSpring31Action class extends org.springframework.web.portlet.mvc.AbstractController
    class and implements handleRenderRequestInternal method, inside this method i am not executing any business logic instead i am creating object of ModelAndView, setting userName attribute to it and then forwarding control to hello.jsp. Inside the hello.jsp the userName object would be available in renderRequest

  8. Last step is to create hello.jsp inside /WEB-INF/jsp folder like this

    &tl;%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" session="false"%≷
    <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%≷
    <portlet:defineObjects /≷
    <h1≷Hello From Hello Spring 2.0.8 &tl;%=renderRequest.getAttribute("userName") %≷ < /h1≷

    The hello.jsp is very simple only thing that it does is read value of userName attribute set by HelloSpring31Action from renderRequest and display it to user,



Spring Framework 3.0.1 has support for Portlet Specification 2.0

Yesterday i was talking with my friend Sanjay and he said that Spring Framework Release 3.0.1 has Support for Portlet Specification 2.0. Today i looked at the documentation of Dispatcher, i can see that it has method like serveResource(), doEventService()