<cfcomponent output="false">
<cffunction name="init" output="false">
<cfargument name="dsn">
<cfargument name="globals">
<cfargument name="globals2">
<cfargument name="mailto">
<cfargument name="fw" type="struct" required="true">
<cfset variables.fw = arguments.fw>
<cfset variables.dsn = arguments.dsn>
<cfset variables.globals = arguments.globals>
<cfset variables.globals2 = arguments.globals2>
<cfset variables.mailTo = arguments.mailto>
<cfreturn this>
</cffunction>
<cffunction name="calledFromCommon" access="public" output="false">
<cfreturn "Here">
</cffunction>
</cfcomponent>
<cfoutput>
<p>Banking page</p>
<cfset application.painter = "Cats">
<cfif IsDefined("commonService.calledFromCommon")>
<cfset mme = commonServices.calledFromCommon()>
YES!!!
<cfelse>
NO
</cfif>
</cfoutput>
Hi Karen! Welcome to FW/1!
Lots of questions in there so let’s see what I can do about answering them. I’ll start with the easiest one:
If there a method to learn more about the runtime exception by altering the stock error page (a vanilla error page I got from the web)?
For development purposes you could add <cfdump var=”#request.exception#”> to error.cfm to see a full dump of the exception which will probably help.
if from what I posted is there anything that appears incorrect?
One thing that stands out is that you have commonService in one line and commonServices in the next:
<cfif
IsDefined("commonService.calledFromCommon")>
<cfset
mme
=
commonServices.calledFromCommon()>
Off-the-top-of-my-head, I’m a bit surprised the service and method are defined in the view – views are executed in the context of FW/1 so they wouldn’t normally see services (and in normal Model-View-Controller code you would not call services from a View, only from a Controller).
Do you have a controllers/main.cfc file? The normal flow would be for that to have a bank function – to match action=main.bank which leads to views/main/bank.cfm – and FW/1 would call the main controller’s bank function, passing in the request context (rc), and that function would call services to populate data into the rc:
rc.mme = variables.commonService.calledFromCommon();
And then the views/main/bank.cfm file would reference that as #rc.mme#
To make the magic service injection work, main.cfc would need either a setter for the service:
function setCommonService( commonService ) {
variables.commonService = commonService;
}
Or you could use property injection instead, by adding accessors=true to your component tag and including a property declaration for the service:
property commonService;
(Your code is all tag-based and I haven’t written CFCs like that for so long I’m not sure I’d get the tag syntax right, so you’ll have to take my script code above and rewrite it as the appropriate tags, if you’re going to keep your CFCs in tag syntax)
Hope that helps you move forward!
Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
Next up, yes I added a (s) to commonService and since removal of the (s) it’s working now.
Excellent!
First off, I’m using tag based simply because the developers in this company have been using tags forever while I prefer your method coming from a C#/JavaScript background I don’t want to rock the boat in my first few months here but instead when a new app is needed introduce non tag based coding.
Good approach 😊
Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood