RE: [coldbox:12037] Getting the full name of the Event while in runEvent()

Bob, it does look like there is no way that I can find to get the actual running event name inside of a runEvent(). If you look in the runEvent() method in the ColdBox controller you’ll see if that event name you’re looking for is contained within the ehBean object, but that is a local variable to that method and is not available inside the event in any way.

I was about to suggest that we place a reference to ehBean in the private request collection, but I’m not sure if that would really be right. For instance, I wouldn’t ever need to know what event was being run inside a handler, because-- well, that’s where I am right now. Perhaps a view might want to know what handler ran it, but handlers don’t really run views when they do event.setView(), the view gets rendered later on the life cycle. Now, it is possible to ask the renderer plugin to render a view directly in a handler, but then again you could technically render a view outside of a handler all-together. The last complication is that you can runEvent() inside a runEvent() which would create a chain of recursive event calls and which one would be in the prc at a given point in time?

I’ll admit I don’t fully understand what it is you are wanting to do. I got a little lost with ‘improve the presentation of the output data with "this part from " and "this other part from " as far as just exactly how you were creating that info.’

If I had to do something like that, I think I would use an interceptor. If your interceptor listens on preEvent and postEvent then it will know what is being run and, assuming it is scoped to the request, it can can maintain the call stack of what is currently running. Add a custom interception point for adding something to your log. Don’t forget that an interceptor has its own stringBuffer you can append to over the course of a request. In your post handler you can retrieve that info from the interceptor and use it. Just a thought…

Thanks!

~Brad

Brad,

Here's an expanded version of my sample code (but still greatly
simplified for purposes of illustration). Now, we could argue all day
long about how I went about this and looking at this simplified
example, one might certainly wonder why anyone would do it this way.
I'll just say that my app (written along the lines of this example)
works quite well.

If run with event=HandlerA.eventA,doEventB=true the following output
is produced:
{
    "HandlerA.eventB": {
        "EVENTB_DATA1": 123,
        "EVENTB_DATA2": 456
    },
    "HandlerA.eventA": {
        "EVENTA_DATA1": "abc",
        "EVENTA_DATA2": "def"
    }
}

Obviously, the handler name generated while eventB was running is that
of HandlerA. Let me repeat what I've said before: I do NOT regard
this as a Coldbox error. getCurrentHandler() is returning EXACTLY
what it is supposed to return - then name of the currently requested
event handler. I'm just looking for a way to get the "currently
running" event as opposed to the "requested" event.

The commented line in the postHandler produces exactly the output I
need so I'm good to go here.

Thanks,
Bob

myInterceptor.cfc
component output="false" extends="coldbox.system.Interceptor" {
  public void function preProcess(any event, struct interceptData )
output=false {
  var rc = event.getCollection();
  if (isdefined("rc.doEventB")) {
    runEvent(event="HandlerB.eventB");
  }
  }
  public void function postEvent(any event, struct interceptData )
output=false {
  var prc = event.getCollection(private=true);
  event.renderData(data=prc.resultStruct, type="JSON");
  }
}

BaseHandler.cfc
component {
  function postHandler(event, action, eventArguments) {
  prc = event.getCollection(private=true);
  prc.resultStruct["#event.getCurrentHandler()#.#action#"] = prc.result;
  //prc.resultStruct["#listLast(getMetaData(this).name,".")#.#action#"]
= prc.result;
  }
}

HandlerA.cfc
component extends="BaseHandler" {
  function eventA(event, rc, prc) {
  prc.result = {eventA_data1="abc", eventA_data2="def"};
  }
}

HandlerB.cfc
component extends="BaseHandler" {
  function eventB(event, rc, prc) {
  prc.result = {eventB_data1="123", eventB_data2="456"};
  }
}