[coldbox-2.8.1] Module reference syntax in runEvent

Guess I have less of a handle on this than I thought. So I have a module that is loaded dynamically through an interceptor during OnAppInit that is based on the http host. Module loads perfectly and if you access the coldbox debug panel link for the entry point (“account”) and http://domain/index.cfm/account goes to home.index in the account module…as it should.

However, in my layout file (shared with modules), I have a breadcrumb display area that modules will override from the default used outside the module so in the layout code, I want to to

runEvent(event=“account/home/navigation”, prepostExemp=true)

another module specific handler/action and when it hits that code I’m told that

The event: account/home/navigation is not valid registered event

but in both cases account/home/index or account/home/navigation work just fine in the browser. This suggests to me that I’m doing something wrong in the syntax of the event attribute to runEvent? Maybe? What am I doing wrong?

Mike

Try “account:home/navigation”

I believe the problem is that when you come in form the URL, the SES interceptor parses the route and extracts the module entry point. When simply calling runEvent(), the controller expects the module entry point to already be denoted with the “:”.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad (ps…3.8.1 NOT 2.8.1…typo in subject).

However, same error…Here is the runEvent command:

runEvent(event=“account:home/navigation”, prepostExemp=true)

the handler in the module (home):

component {

function index(event,rc,prc){
event.setView(“home/index”);
};

function navigation(event,rc,prc) {
return renderView(“home/navigation”);
};
}

System handler (code root, not module)

function onAppInit(event, rc, prc) output=“false” {

announceInterception(‘onAfterAppInit’, {});
};

Interceptor call to load and active module:

moduleservice.registerAndActivateModule("#acct.host()#",“accounts”);

and the module, other than setting entrypoint, name and applying the default layout, is all default from the application template. I have not touched any routing mechanisms.

could this be wholly the wrong way to approach this and I’m just now discovering it? Since I basically want to have one set of code, the account modules are really designed as overrides…if they exist, they’ll override settings or display “stuff”, though they will be used for custom solutions that sit outside the core site functionality.

Mike

It may be this:

account:home.navigation

Yep, here it is in the docs :slight_smile:
http://wiki.coldbox.org/wiki/Modules.cfm#Module_Event_Executions

I don’t think you’re doing anything fundamentally wrong. I think you just need to tweak the right syntax.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yeah, I saw that too…one of the first things I tried…still get:

Application Execution ExceptionError Type: HandlerService.EventHandlerNotRegisteredException : [N/A]

Error Messages: The event: account:home.navigation is not valid registered event.

Brad,

So I moved some things around a little bit, learned a couple things about when and where to put and load modules and everything works except this:

In my main application, I want to include a bit of rendered output from an event in a module. In my view I include:

#runEvent(event=“test:home.navigation”)#

which does not give me any errors. If I attempt to browse to index.cfm/test/home/navigation, I get the proper data output. The modules handler for test:home.navigation is:

function navigation(event,rc,prc) {
// return “lovely, I return a string”;
return event.renderData(data=renderView(“home/navigation”), type=“HTML”);
// return renderView(“home/navigation”);
// event.setView(“home/navigation”);
};

ALL of these work if I use the url to browse right to it, each with slight various in the output. The one I want to work is the uncommented one so that all it returns back (correctly) is the rendered view and nothing else. However, when accessed via the runEvent, I get an error:

Error Type: MissingInclude : [N/A]
Error Messages: Could not find the included template //views/home/navigation.cfm.

The //views suggests something is missing, part of the path…like because the runEvent is happening from the main application, in a view no less, that it does not know how to get to the view…but I don’t know what it could be wanting. This example, by the way, comes from a test module just as you had created…and other than this is responding exactly how I expected it to work.

Oh… and return “Lovely, I return a string” DOES work with the runEvent, by the way.

Mike

Yes that is correct behavior. If you want to call a runEvent() inline and have the contents of the view returned directly, you need to actually have a return statement in the action.

The way your action is set up now, it simply sets the view into the prc for later rendering, which of course, never will happen since this isn’t the main event for the page.

I usually do it like this:

function myAction(event,rc,prc) {
var dataForView = service.getData();
return renderView(“view”, args=dataForView1);
}

Note that I actually render the view right there and return its output. Using args isn’t a requirement, but I like it since it doesn’t pollute the rc and keeps the event completely self-contained.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

pass in the module name as an arg.

return event.renderData(data=renderView(view=“home/navigation”,module=“test”), type=“HTML”);

Ahh, yes-- sorry, all the commented out lines threw me and I thought the event.setView(“home/navigation”); line was the one running.

Aaron is correct that there is a module argument to render view. Check out frameworksupertype’s renderView method int he API docs.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yes, that works properly. Actually I had looked at this, but it did not make any sense to have to pass the module parameters from a renderView INSIDE the modules event structure. Perhaps renderView is not the best way to get a vanilla render of a module view from outside the module in this instance? In any event, the end result in this case is exactly the behavior I was looking for / expecting. Thank Brad, Aaron.

Mike