blog | bio | agenda | jobs | ajaxCFC

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].

Related Blog Entries

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?CCB13119-3048-7431-E40C67E886488D2E

Comments
Rob,
Do you plan to update ModelGlue-d version of AjaxCFC with the latest changes?
# Posted By Jura Khrapunov | 3/7/06 8:10 AM
Jura, I sure will, but the real question is when. I have been working with never and improved examples and functionality for Model-Glue, but because of time management constrains I haven't finished yet. I'm hoping I can dedicate some time towards that in the next few weeks. Please bear with me; thanks!
# Posted By Rob Gonda | 3/7/06 11:05 PM
:-(. Anyway - keep up, AjaxCFC is really nice piece of software, I appreciate your time spent on it.
# Posted By Jura Khrapunov | 3/10/06 9:28 AM
I finally got around to updating CFCAjax on my development machine. It worked fine on coldfusion, but not in BlueDragon. The return gives a Status 200, but the response is the following error:

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!
# Posted By John Schroeder | 4/5/06 7:34 PM
John, thanks for the tip ... It was working with BD until this version ... man, I wonder what made it break ... any chance I can borrow some space in a Blue Dragon Dev Environment to make it compatible again? Should be simple if I had one ... Greatly appreciated.
# Posted By Rob Gonda | 4/6/06 10:20 PM
Definitely breaks my code. Problem is I can't get it to work again. I am passing 2 parameters into my CF function. Are you saying that you need 2 cfargument tags in my function? That doesn't work, I get this error: "Invalid reply from server"

DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'expandStudentResults', x,y, doExpandResults);

<cfargument name="x" type="numeric" required="yes">
<cfargument name="y" type="numeric" required="yes">
# Posted By Mitch Rubin | 4/18/06 2:28 PM
To follow up on my last post, yes you do need 2 cfargument tags, I did get that to work.

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.
# Posted By Mitch Rubin | 4/18/06 7:47 PM
Mitch, it's not that they have to be all lowercase, but JS is case sensitive and the columns carry the same case that they have in your database.
# Posted By Rob Gonda | 4/22/06 7:33 PM
Any chance you could update the pdf docs to include this feature? I'm new to this package and don't quite follow what you are saying. Also, it looks like your wiki got trashed.
# Posted By Mark | 6/16/06 2:26 PM
Mark,

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
# Posted By Rob Gonda | 6/16/06 5:02 PM
I just ported my app over to ajaxCFC from CFAJAX, very please overall but I am having a serious problem with arguments... I just dont understand it, looks like a bug, some of the arguments come through as expected, but despite having the same names (in case and everything) and specified in the same order, it constantly mixes up the argument values, companyid is fine, but all the other values are in the wrong order, anybody got any ideas? I dont want to use a structure or anything because that removes any benefit of named arguments.


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>
# Posted By Sean Dearnaley | 6/21/06 10:02 AM
Sean,

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
# Posted By Rob Gonda | 6/22/06 1:46 AM
cheers Rob, I'll give that a go and let you know how it works out... thanks again for the product, it's much nicer than CFAJAX. I'm rewriting all my apps...
# Posted By Sean Dearnaley | 6/22/06 10:19 AM
Sean,

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.
# Posted By Rob Gonda | 6/22/06 11:08 AM
Hey Rob,

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
# Posted By Sean Dearnaley | 6/24/06 2:51 AM
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
# Posted By Rob Gonda | 6/24/06 1:48 PM
Sean, I just released the update. The parseURL wasn't the only change, that's why it didn't work for you. I still need to fix the unnamed to named translation for over 10 items, but at least now you may pass real named arguments, allowing for optional args in your cffunction.
# Posted By Rob Gonda | 6/25/06 6:59 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.