passing Event collection to nested handlers and other things

I am wondering how to have a handler that gets init'd by another
handler see the Event collection.

So I have a parent Handler

<cfcomponent name="general" extends="coldbox.system.eventhandler"
         <cffunction name="dspDashboard" access="public"
returntype="void" output="false" hint="Not USING">
    <cfargument name="Event" type="coldbox.system.beans.requestContext">
    <!--- RC Reference --->
    <cfset var rc = event.getCollection()>

    <!--- runevent to ehDashboard to retrieve dashboard component
information --->
      var dashBrd = createObject("component","handlers.ehDashboard").init
      var userDatap = structNew();
      // Call ehDashboard methods to generate data packets
      dashBrd.getAlerts(userDatap) ;

    <!--- Do Your Logic Here to prepare a view --->
    <cfset Event.setValue("welcomeMessage","Welcome to ColdBox!")>
    <cfset Event.setLayout("Layout.Dashboard")>
    <!--- Set the View To Display, after Logic --->
    <cfset Event.setView("vwDashboard")>



child function in ehDashboard

<cffunction name="getAlerts" displayname="getAlerts" hint="get Alerts"
access="public" output="false" returntype="Any">
    <cfargument name="Event" type="coldbox.system.beans.requestContext">
    <cfargument name="userData" type="Struct" required="false" />
    <!--- TODO: Implement Method --->
      var rc = event.getCollection();
      var alertData = StructNew();
      //var userData = arguments.userData ;
      var sortOrder = 'DESC';
      if (structKeyExists(userData,'sortOrder')){
        sortOrder = userData.sortOrder;
      getAlertsobj = createObject("component","model.pba.dashboard");

      alertData.smartAlerts = getAlertsobj.getAlerts
      alertData.pbaAlerts = getAlertsobj.getAlerts(2,userData,sortOrder);
      alertData.cpsAlerts = getAlertsobj.getAlerts(3,userData,sortOrder);

    <cfreturn alertData />

So what I want to do is acccess the "rc" directly in dashBrd.getAlerts
(). I know I can pass "rc" and probably should do that anyways. But,
I have wondered why sometimes I cannot use Event.getCollection().
Probably the fact still understanding framework and some OO concepts.

Thanks for any insight

No offense meant, but I am extremely confused (errr… QuackFuzed) by what you’re attempting to do. If you’re trying to run another event, you do so like this…

var rc = event.getCollection(); runEvent("handler.event");

There is no createObject() call or anything like that.

I am with Matt. You are doing too much work and basically taking on the responsibility of the handler life cycles.

If you need to chain an event, use runEvent()


Must get sleep. :slight_smile: OMG, yeah totally forgot. And here at my day job I
do just that, heck even tell my developers to do that.

Thanks for stating the obvious, On that do have a similar question.

I created a plugin based off your hello example and, probably due to
lack of understanding, was trying to access the same above scope.
In the handlers and interceptors I usually just add the extra "Event"
argument and be done. Yet was not able to so did this

var rc = controller.getRequestService().getContext().getCollection();

I am sure that is the wrong way to do it, just not sure the right way.


var rc = controller.getRequestService().getContext().getCollection();

^ is the correct way to get the request collection in a plugin. :slight_smile:

Scary I am learning.. Thanks Matt

Heh. No problem. :slight_smile: