ajaxCFC significant update: named arguments
I just uploaded a new release of ajaxCFC, and this one carries a rather significant update. I modified the way you pass arguments from JavaScript to your ColdFusion function. Before, due to that you were passing unnamed arguments, you were receiving them in a ColdFusion arguments array; Thanks to Kenton Gray's contribution now you receive all arguments as separate named arguments. The main seller was that you could have built-in validations ... I’m using metadata to retrieve the names of the declared arguments, and if you’re passing more arguments than you declare, they come in as ‘unkwnownXX’, xx being a counter or unknowns. I tested the code in CFMX6, 6.1, and 7, but not yet in Blue Dragon. If any of you could do that for me, it would be greatly appreciated.
Your old code WILL NOT WORK with the new ajax.cfc. You can make it work by one of two methods:
1) name your arguments and their names in your CF Function. This method is the most advisable.
2) 2 :: the quick method) Remove the args declaration and use the arguments scope as an array by simple removing the args var… use arguments[1] instead of args[1].
Your old code WILL NOT WORK with the new ajax.cfc. You can make it work by one of two methods:
1) name your arguments and their names in your CF Function. This method is the most advisable.
2) 2 :: the quick method) Remove the args declaration and use the arguments scope as an array by simple removing the args var… use arguments[1] instead of args[1].
TrackBacks
There are no trackbacks for this entry.
Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?CCB13119-3048-7431-E40C67E886488D2E
http://www.robgonda.com/blog/trackback.cfm?CCB13119-3048-7431-E40C67E886488D2E









Do you plan to update ModelGlue-d version of AjaxCFC with the latest changes?
alert('An error has occurred:\nMessage:Parameter isn\'t of type COMPONENT');
var _5276_1144279646296 = null;
DWREngine._handleResponse('5276_1144279646296', _5276_1144279646296);
Callback:
function () {
DWREngine._stateChange(batch);
}
I'll poke around a bit, but any suggestions or help would be great :)
I saw you posted the suggest function as well - hope it was some help!
DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'expandStudentResults', x,y, doExpandResults);
<cfargument name="x" type="numeric" required="yes">
<cfargument name="y" type="numeric" required="yes">
Also, I didn't realize that the column names that are used in the call back function must be all lower case. I was using mixed case for longer column names and I got "undefined" as my table cell data. It took a while to figure that out.
You're right. I'll try to update the docs this weekend. I chose to disable the wiki for now until I or some contributors have time to update it.
Cheers.
~Rob
JS:
DWREngine._execute('components/CertifiedModel.cfc', null, 'updateVerifiedCompany', companyid,companyname,sitephonenumber,contacttitle,contactfirstname,contactmiddleinitial,contactlastname,contactemailaddress,companycity,companyaddress,companyaddresstwo,faxnumber,companystate,companyzip,sendmail,companyurl,updateRecordResult);
<cffunction name="updateVerifiedCompany" output="false" description="Submit Updated Verified Company Registration" access="private" returntype="struct">
<cfargument name="CompanyID" required="true" type="string" hint="CompanyID"/>
<cfargument name="CompanyName" required="true" type="string" hint="companyName"/>
<cfargument name="SitePhoneNumber" required="true" type="string" hint="Phone Number"/>
<cfargument name="ContactTitle" required="true" type="string" hint="Contact Title"/>
<cfargument name="ContactFirstname" required="true" type="string" hint="Contact First Name"/>
<cfargument name="ContactMiddleinitial" required="true" type="string" hint="Contact Middle Initial"/>
<cfargument name="ContactLastname" required="true" type="string" hint="Contact Last Name"/>
<cfargument name="ContactEmailAddress" required="true" type="string" hint="Contact Email Address"/>
<cfargument name="CompanyCity" required="true" type="string" hint="Company City"/>
<cfargument name="CompanyAddress" required="true" type="string" hint="Company Address"/>
<cfargument name="CompanyAddressTwo" required="true" type="string" hint="Company Address Two"/>
<cfargument name="FaxNumber" required="true" type="string" hint="Fax Number"/>
<cfargument name="CompanyState" required="true" type="string" hint="Company State"/>
<cfargument name="CompanyZip" required="true" type="string" hint="Company Zip"/>
<cfargument name="Sendmail" required="true" type="string" hint="Sendmail"/>
<cfargument name="CompanyURL" required="true" type="string" hint="Company URL"/>
<cfset msg = structnew()>
<cfset msg.iserror = "0">
<cfset msg.message = "">
<cfinclude template="inc-lookupgeocode.cfm">
<cfif msg.iserror is "0">
<cftry>
<cfquery name="updateVerifiedCompanyQuery" datasource="#request.dsn#">
UPDATE
tankcompanies_verified
SET
Latitude = <cfqueryparam value="#latitude#" cfsqltype="CF_SQL_FLOAT"/>,
Longitude = <cfqueryparam value="#longitude#" cfsqltype="CF_SQL_FLOAT"/>,
rLatitude = <cfqueryparam value="#rlatitude#" cfsqltype="CF_SQL_FLOAT"/>,
rLongitude = <cfqueryparam value="#rlongitude#" cfsqltype="CF_SQL_FLOAT"/>,
CompanyName = <cfqueryparam value="#arguments.CompanyName#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
SitePhoneNumber = <cfqueryparam value="#arguments.SitePhoneNumber#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
ContactTitle = <cfqueryparam value="#arguments.ContactTitle#" cfsqltype="CF_SQL_VARCHAR" maxlength="15"/>,
ContactFirstname = <cfqueryparam value="#arguments.ContactFirstname#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
ContactMiddleinitial = <cfqueryparam value="#arguments.ContactMiddleinitial#" cfsqltype="CF_SQL_VARCHAR" maxlength="5"/>,
ContactLastname = <cfqueryparam value="#arguments.ContactLastname#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
ContactEmailAddress = <cfqueryparam value="#arguments.ContactEmailAddress#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
CompanyCity = <cfqueryparam value="#arguments.CompanyCity#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
CompanyAddress = <cfqueryparam value="#arguments.CompanyAddress#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
CompanyAddressTwo = <cfqueryparam value="#arguments.CompanyAddressTwo#" cfsqltype="CF_SQL_VARCHAR" maxlength="150"/>,
FaxNumber = <cfqueryparam value="#arguments.FaxNumber#" cfsqltype="CF_SQL_VARCHAR" maxlength="25"/>,
CompanyState = <cfqueryparam value="#arguments.CompanyState#" cfsqltype="CF_SQL_VARCHAR" maxlength="2"/>,
CompanyZip = <cfqueryparam value="#arguments.CompanyZip#" cfsqltype="CF_SQL_VARCHAR" maxlength="5"/>,
Sendmail = <cfqueryparam value="#arguments.Sendmail#" cfsqltype="CF_SQL_tinyint"/>,
LastUpdated = <cfqueryparam value="#now()#" cfsqltype="CF_SQL_timestamp"/>,
CompanyURL = <cfqueryparam value="#arguments.CompanyURL#" cfsqltype="CF_SQL_VARCHAR" maxlength="200"/>
WHERE
CompanyID = <cfqueryparam value="#arguments.CompanyID#" cfsqltype="CF_SQL_CHAR" maxlength="9"/>
</cfquery>
<cfset msg.iserror = "0">
<cfset msg.message = "<div class=successmsg>Company Updated</div>">
<cfcatch>
<cfset msg.iserror = "1">
<cfset msg.message = cfcatch.message>
</cfcatch>
</cftry>
</cfif>
<cfreturn msg>
</cffunction>
Just found the problem! I never tested the unnamed arguments array with more than 10 elements... it names them C0-PARAM[N], where N is a single digit number... and sort them alphabetically. I just added it to my bug list and will probably fix it this weekend... should be an easy one.
In the same token, I added a new but useful rule to the engine... if you send a single object of named values it will pass it as individual arguments to your CFC instead...
i.e.
var _o = {foo: "bar", baz: "thud"}
DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'method', _o, methodResult);
<cffunction name="method" output="no" access="private">
<cfargument name="foo" />
<cfargument name="baz" />
<cfreturn true />
</cffunction>
That's the way I've been using it lately....
Best,
~Rob
Sorry, just to make it clear... I added this new rule, but I haven't released it yet. ... but if you need it right away, use this at the end of the parseURL function inside ajax.cfc
<cfif arrayLen(params) eq 1 and not isSimpleValue(params[1])>
<cfset result.arguments = params[1] />
<cfelse>
<cfset result.arguments = params />
</cfif>
Cheers.
I got a chance to try it... no joy I'm afraid... I added the code to the parseURL function just before the cfreturn... the javascript object gets passed in ok... but the cfc only gets one argument passed to it, and it's a structure with all the items in the correct order... but no named arguments work... I guess I could just use one argument for now but it would be nice to use the built in validation. thanks again for your help.
-sean
I'll release the one working like I mentioned this weekend... I know it works cuz I have it working just like that here: http://www.robgonda.com/dev/rss/
Best,
~Rob