ProcessEvent annotation

This is how the default implementation of the processEvent() method in GenricPortlet looks like,

public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
String eventName = request.getEvent().getQName().toString();
try {
// check for exact match
Method eventMethod = processEventHandlingMethodsMap.get(eventName);
if (eventMethod != null) {
eventMethod.invoke(this, request, response);
} else {
// Search for the longest possible matching wildcard annotation
int endPos = eventName.indexOf('}');
int dotPos = eventName.lastIndexOf('.');
while (dotPos > endPos) {
String wildcardLookup = eventName.substring(0, dotPos + 1);
eventMethod = processEventHandlingMethodsMap.get(wildcardLookup);
if (eventMethod != null) {
eventMethod.invoke(this, request, response);
if (dotPos == 0) {
dotPos = eventName.lastIndexOf('.', dotPos - 1);
} catch (Exception e) {
throw new PortletException(e);
// if no event processing method was found just keep render params

First it tries to figure out if there is a method with @ProcessEvent annotation, that matches current event, if yes it forwards control to that method if not it sets the current render parameters as new render parameters.

You can annotate a method use ProcessEvent annotation using two different approaches

  • Using QName: You can specify the fully qualified name of the event using "{" + Namespace URI + "}" + local part format. Ex. @ProcessEvent(qname="{}hello")

  • Using local Name:For using only the local part of the event name and leverage the default namespace defined in the portlet deployment descriptor with the default-namespace element the following alternative is provided: @ProcessEvent (name=), where the event name is only the local part.

You can download the sample portlet that i built to demonstrate how to use @ProcessEvent from here

package com.webspherenotes.portlet.jsr286;


import javax.portlet.Event;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.ProcessEvent;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;


public class ProcessEventAnnotationPortlet extends GenericPortlet {

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering ProcessActionAnnotationPortlet.doView()");
Contact contact = (Contact) request.getPortletSession().getAttribute(
if (contact != null) {
"First Name " + contact.getFirstName() + "
Last Name "
+ contact.getLastName() + "
Email "
+ contact.getEmail());
} else {
response.getWriter().println("Contact not found in session ");
System.out.println("Exiting ProcessActionAnnotationPortlet.doView()");

//@ProcessEvent(name = "hello")
public void handleContactEvent(EventRequest request, EventResponse response)
throws PortletException, IOException {
.println("Entering ProcessActionAnnotationPortlet.handleContactEvent()");
Event event = request.getEvent();
System.out.println("Event Name " + event.getName());
System.out.println("Event Value " + event.getValue());
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);
.println("Entering ProcessActionAnnotationPortlet.handleContactEvent()");


The ProcessEventAnnotationPortlet can act as target of hello event. It has a handleContactEvent method that can be used for handling the hello event. I can annotate it using either only local name like this @ProcessEvent(name = "hello") or using fully qualified name like this @ProcessEvent(qname="{}hello")

This is the portlet.xml for my Sample portlet

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns=""
version="2.0" xmlns:xsi=""
<display-name>Process Event Annotation Portlet</display-name>
<title>Process Event Annotation Portlet</title>
<short-title>Process Event Annotation Portlet</short-title>
<keywords>Process Event Annotation Portlet</keywords>




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... 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