If I use access="remote" for binding a cfselect to a cfc, then I lose the ability to have an Init() constructor.
<cfselect name="CityID" bind="cfc:Components.City.View1({StateID})" value="CityID" display="CityName" bindonload="yes" />
I'm used to passing the datasource name to the Init function when I instantiate a component, like so:
<cfcomponent>
<cffunction name="Init">
<cfargument name="DS">
<cfset Variables.Instance.DS = arguments.DS>
<cfreturn This>
</cffunction>
<cffunction name="View1">
<cfset var qry = "">
<cfquery name="qry" datasource="#Variables.Instance.DS.Datasource#">
SELECT *
FROM Table
</cfquery>
<cfreturn qry>
</cffunction>
</cfcomponent>
Phillip, what I usually do in this scenario is:
onApplicationStart:
<cffunction name="onApplicationStart">
<cfset application.dsn = "myDSN" />
<cfset application.cityFinder = createObject("component", "Components.City").init(application.dsn) />
</cffunction>
And the remote proxy CFC:
<cfcomponent displayName="CityFinderProxy">
<cffunction name="View1">
<cfargument name="StateId" />
<cfreturn application.cityFinder.View1(argumentCollection=arguments) />
</cffunction>
</cfcomponent>
Note that I've left out a lot of best-practices (i.e. specifying argument types, required, etc) for brevity... so don't just copy and paste this example. I just wanted to illustrate the idea.
What is the question, exactly?
Setting a CFC to remote is basically making it a web service, so I guess that is why you wouldn't have the init() constructor.
You could easily set the datasource name in an application/session variable that created in the onApplicationStart portion of your application.cfc file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With