Initiate events in portlet (CFC)

You publish events in the processAction() method of the portlet code by calling setEvent() on the ActionResponse object. This setEvent() method takes two parameters: the QName of the event object and the type of object defined in portlet.xml.

Following is an example of processAction() method.

<cffunction name="processAction" returntype="void" access="public" output="false" hint="Called by the portlet container to allow the portlet to process an action request."> 
<cfargument name="actionRequest" type="any" required="true" hint="A javax.portlet.ActionRequest java object"> 
<cfargument name="actionResponse" type="any" required="true" hint="A javax.portlet.ActionResponse java object"> 
<cfset super.processAction(arguments.actionRequest, arguments.actionResponse)> 
<!--- send event notification ---> 
<cftry> 
<cfset arguments.actionResponse.setEvent("HelloEvent", request.portlet.parameters.event_value)> 
<cfcatch type="any"> 
<cflog file="simple-event-portlet" type="error" text="processAction() threw exception: #cfcatch.message#"> 
</cfcatch> 
</cftry> 
</cffunction>

Capture events in processEvent() method:

<cffunction name="processEvent" returntype="void" access="public" output="false" hint="Called by the portlet container requesting the portlet to process a specific event."> 
<cfargument name="eventRequest" type="any" required="true" hint="A javax.portlet.EventRequest java object"> 
<cfargument name="eventResponse" type="any" required="true" hint="A javax.portlet.EventResponse java object"> 
<cfset var e = StructNew()> 
<cftry> 
<cfset e.name = arguments.eventRequest.getEvent().getName()> 
<cfset e.value = arguments.eventRequest.getEvent().getValue()> 
<cfif NOT IsDefined("application.EventReceivingPortletEvents")> 
<cfset application.EventReceivingPortletEvents = ArrayNew(1)> 
</cfif> 
<cfset ArrayAppend(application.EventReceivingPortletEvents,e)> 
<cfcatch type="any"> 

</cfcatch> 
</cftry> 
</cffunction>

 Adobe

Get help faster and easier

New user?