As most of you have already seen, the normal "template" for onRequest is as follows:
<cffunction name="onRequest" returnType="void">
<cfargument name="thePage" type="string" required="true">
<cfinclude template="#arguments.thePage#">
</cffunction>
But since ajax and webservices are actually CFC methodology this included code will break it.
Now I am not sure if the following cures all scenarios, but it gave me the ability to do webservices / ajax.
<cffunction name="onRequest">
<cfargument name = "targetPage" type="String" required=true/>
<cfif Right(arguments.targetPage,3) EQ "cfc">
<cfparam name="url.method" default="">
<cfset variables.component = Left(arguments.targetPage,Len(arguments.targetPage)-4)>
<cfset variables.component = Replace(variables.component,"/",".","ALL")>
<cfinvoke method="#url.method#" component="admissions.#variables.component#" returnvariable="methodOutput">
<cfif IsDefined("methodOutput")>
<cfwddx input="#methodOutput#" output="wddxOutput" action="cfml2js" toplevelvariable="rtnData">
<cfoutput>#wddxOutput#</cfoutput>
</cfif>
<cfelse>
<cfinclude template="/admissions/#Arguments.targetPage#">
</cfif>
</cffunction>
Notice two things:
- The onRequest page now checks to see the extension of the file being requested (CFC or CFM). If it is a CFC it invokes a method instead of including it.
- The CFC section if the function 'RETURNS' it output, using the cfreturn tag, then we need to convert it to WDDX. This is the standard CF methodology.
1 comments: