Odd ColdFusion Ajax binding error?

This post is more than 2 years old.

Brett asks:

Hope all is well, I have a CF8 issue and I was hoping that you might have a work around. I have a cfselect that is bound to another cfselect. In the second cfselect I pass two parameters to the function called in the bind. The second parameter is a comma seperated list and it is causing all kinds of errors that i am passing two many arguments to the cfc.

<cfselect name="market" id="market" class="Normal"
required="YES"
bind="cfc:COM.LocalJobs.GetMarkets({specialty},'#Form.Market#')"
display="Market"
value="Market"
bindonload="Yes"
multiple="yes">
</cfselect>

The value that is being passed back to the cfc (Form.Market) is a multiple slection from this cfselect. This is what is causing the error. Have you come acrossed anything in your journey that might help resolve this?

The first thing I did was create a simple example so I could test. I began with this file:

<cfset x = "alpha"> <cfform name="mainform"> <cfinput name="first"> </cfform> <cfdiv bind="cfc:test.stringconcat({first},'#x#')">

And then wrote my CFC method to just return the combination of the two arguments sent:

remote any function stringconcat(a,b) { return a & b; }

I ran the code to make sure it worked as is. When entering "foo" into the form field the div display fooalpha, as expected. I then edited x to be alpha,beta and immediately got:

You cannot specify more arguments to a CFC function than it declares.

Error parsing bind cfc:test.stringconcat({first},'alpha,beta')

What the heck? It's clearly passing two arguments. But get this. I modified my CFC to temporarily allow for a third arg. When I did that and viewed source on the CFM, I saw this in the JavaScript:

'bindExpr':[['a','first','','value'],['b','alpha],['c',beta']]

For some reason ColdFusion assumes that I am trying to pass additional arguments. If I didn't have single quotes around them I could see that. The result would have been something like {first},alpha,beta. I tried to "trick" the compiler. I used "'alpha','beta'". I used a space between the words and the comma. Nothing worked. I finally recommended he use another delimiter. Depending on the nature of your data that may or may not be acceptable. He suggested a semicolon and I can confirm it works.

So obviously this is a bug - right? Has anyone seen this before and come up with a nicer workaround?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Ben Doom posted on 7/16/2010 at 3:06 AM

You could try using urlEncodedFormat() to encode the data in the second param. You could then use traditional comma delimited lists, and only need one function call on each end of the cfc call. Not tested, YMMV.

Comment 2 by Brett posted on 7/16/2010 at 4:53 AM

Ray, I was able to make it work using a replace to change the delimiter to a semi-colon and then loop through the selections to retrun them to the top of the list, however since the selected parm does not work in a cfselect that uses a bind I can get the selected items to remain selected, has anyone found a work around for that issue? thanks again for all the help.

Comment 3 by Raymond Camden posted on 7/16/2010 at 6:49 AM

By any wild chance did you try Ben's solution?

Comment 4 by Brett posted on 7/16/2010 at 7:01 AM

No, I was able to get the data to the CFC with out issue by just changing the delimiter. So I did not see any reason to try that. Would that affect the issue i am having how with the selected items not reamining selected?

Comment 5 by Raymond Camden posted on 7/16/2010 at 7:04 AM

Don't know - but can't hurt?

Comment 6 by Brett posted on 7/16/2010 at 7:33 AM

@Ray, Bens solution worked fine, I encoded it in the bind statement and then decoded it in the cfc. It is much cleaner than the way i was doing it and that is good, but it is still not holding the selected values when the page submits. If anyone has a work around for this it would be greatly appriciated.

@Ben, thanks for the suggestion it worked great, left me with a new problem but worked and is very clean.

Comment 7 by Dan G. Switzer, II posted on 7/16/2010 at 4:05 PM

I thought this might be a case of needing jsStringFormat() around the variable X, but I just tested and got the same issue.

I suspect the problem is the validation parser isn't strong enough and isn't properly ignoring commas inside a quoted string, but is instead just counting all the commas that appear in the output.

Comment 8 by Christopher Walker posted on 6/26/2012 at 6:59 AM

You weren't using spry were you? I had this issue when I loaded my js libraries from application.cfc onRequestStart. Turned out that that I had a stray js libraries called in included pages and I was calling the functions more than once and the error was thrown. I took me about 3 solid days of console debugging before I saw it.