Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion Query loop works in cf10 but not 9

Why does the following work in CF10 but not CF9?

<cfset out="">
<cfif isQuery( arguments.values ) >
    <cfloop query="#arguments.values#" >            
        <cfset out = '#out#<option value="#value#">#label#</option>'>
    </cfloop>
</cfif>

CF9 states that "Complex object types cannot be converted to simple values." for the line containing the cfloop. I'm using the Coldbox framework and it's debugger information shows that arguments.values is a query with Label & Value columns.

like image 221
Aaron Avatar asked Dec 21 '12 00:12

Aaron


1 Answers

Prior to CF10, the query attribute of cfloop can only be a string - the name of the query - not the variable itself.

So, when you put #arguments.values# it is trying to convert the complex query object to a string, to obtain a name, which is where the error comes from.

It works in CF10 because the attribute has been updated to also allow a query value.


side notes:

This line of code can be simplified:

<cfset out = '#out#<option value="#value#">#label#</option>'>

to:

<cfset out &= '<option value="#value#">#label#</option>'>

Also you very likely should be using HtmlEditFormat* on at least label, and perhaps value too.

*(or encodeForHtml if it only needs to work in CF10+)

like image 140
Peter Boughton Avatar answered Nov 05 '22 22:11

Peter Boughton