Domanda

I have a search form in ColdFusion. On post, it invokes a SQL stored procedure. It returns the first 20 matching records by default, and accepts a "pagenum" parameter (in addition to many other input parameters) that allows you to indicate which set of 20 you'd like to see (for pagination). For some reason, this code achieves the desired results:

<cfset form["pagenum"] = 3 />

While this doesn't seem to have any effect at all:

<cfset form.pagenum = 3 />

I was under the impression that these 2 lines of code are exactly the same, and the only reason you'd want to use the brackets notation is if you had unusual characters in the variable that aren't allowed in the dot notation. So why am I getting different results for these 2 lines of code?

(In case it makes a difference, the stored procedure accepts all the parameters in xml format and then parses them. We have a coldfusion function that we invoke to convert the arguments struct - in this case, form - to xml and pass it into the function.)

UPDATE:

I just noticed that when I use form.pagenum, the key in the struct is in uppercase (PAGENUM), while if I use form["pagenum] it's in lowercase (pagenum). It seems that if you add a value into a struct, the key is defaulted to uppercase. And as XML is case sensitive, this may be what's throwing off the stored procedure...

È stato utile?

Soluzione

<cfset form.pagenum = 3 />

defaults the key to uppercase (PAGENUM), causing an issue in the xml which is case sensitive and is expecting pagenum.

<cfset form["pagenum"] = 3 />

specifies the case of the key and avoids this issue.

Altri suggerimenti

What version of Coldfusion do you use? I tested this with CF10 and the latest railo:

<CFDUMP var="#FORM#">
<cfset form["pagenum"] = 1 />
<CFDUMP var="#FORM#">
<cfset form.pagenum = 2 />
<CFDUMP var="#FORM#">

Output of three dumps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top