ColdFusion 8 Ajax - binding and strings with commas
Now to the problem. Imagine you have a cfgrid that is binding to a cfc, and the cfc returns a query, and that query uses a "WHERE productid IN #arguments.productidlist#". Where arguments.productidlist would be a comma separated list.
The method in the cfc could look something like this (abbreviated - grid arguments removed):
<cfargument name="productidlist" required="true">
<cfquery name="qGetProducts" datasource="somedsn">
SELECT *
FROM products
WHERE productid IN (#arguments.productidlist#)
</cfquery>
<cfreturn QueryConvertForGrid(qGetProducts)>
</cffunction>
Then you have the code with your cfgrid (again abbreviated):
<cfgrid
format="html"
name="productGrid"
pagesize="5"
bind="cfc:productDAO.getProducts('#selectedProducts#')">
etc....
Obviously the selectedProducts list would be created dynamically but for this example I hardcoded it.
Now as long as the list had only one value we're ok. The problem is when there are several items in the list, and thereby having one or more commas in it. Then you will get the error:
You cannot specify more arguments to a CFC function than it declares.
So the commas where read as if they are separating the arguments used in the bind statement, instead of being read as a list.
As I said earlier I've googled for hours to try and find a way to solve this, and I've tried every possible syntax for passing in the list in the bind statement, but no luck.
I guess there is a easy way of doing this - and I would be very thankful if someone could point it out. (It will probably be one of those occasions where I slap my self for not having figured it out).
In the meantime what I ended up doing - which I feel is not a good solution - is the following.
In the cfgrids bind I did this:
Here I'm using the ListChangeDelims() function to remove the commas from the list, and then I revert it in the SQL in the cfc:


Did you try URLEncoding and Decoding the list going in and out?