4

@Devs, Here I'm writing the script based code for my application. While in a development I'm facing issue like Invalid CFML construct found

Sample Code :

<cfscript>
    cfparam(name="userID", default=0);  // Named attributes are accept in script based code.
    cfparam("myName", 'Kannan'); // Without named attributes. It's return the error. 
    writeDump(userID);
    writeDump(myName);
</cfscript>

enter image description here

I'm not sure whether the ACF allowed positional values ( without named parameter ) in cfparam or not in script based coding style.

FYR : We can use writedump like below

writeDump(var = userID);
writeDump(userID);

Both are returning same result. Not only writedump most of the building functions are support named attributes as well as positional attributes.

Likewise why cfparam not supported this things. Correct me if I did any mistake on my cfparam code or misunderstood anything.

Thanks in advance !.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Kannan.P
  • 1,263
  • 7
  • 14

2 Answers2

4

Well, it is quite interesting to see how it works in the background by looking into the cfusion.jar. Since I am not really a Java person, not quite sure my interpretation is right or not. Let me try though.

Inside cfscript any function which starts with cf are considered as a ColdFusion tag instead of a function.

What I see is that like cfparam, you can use more functions(and more) as well.

cfquery
cfsavecontent
cfinclude
cfthrow
cfabort

I was kind of surprised to see the following syntax works in ColdFusion (I am not sure if there are any documentation that details this syntax).

<cfscript>
  cfquery(name="test", datasource=application.dsn){
    writeOutput('select * from user where userid = ');
    cfqueryparam(value="1", cfsqltype='integer');
  };
  cfdump(var=test);
</cfscript>

So to wind up, same way you cannot define a ACF tag with out specifying name for the attribute, any function with in <cfscript> starts with a coldfusion tag name will need named arguments.

Most likely this was implemented for CF9 or later version to get cfscript support. Later versions has its independent implementations of each tag with out a prefix of cf.

like

param name="test" default="";
savecontent variable="errortext" {
  writeOutput("Application: #test#");
}
rrk
  • 15,677
  • 4
  • 29
  • 45
  • Thank your for more explanation @RRK. One more question how I can check these details in cfusion.jar. file. Because I took a look on that jar & extract it. All are class files so could not able to read because it's having 0's & 1's ( binary value ). Then how we can check this info. Is there any other way ? – Kannan.P Nov 08 '19 at 10:44
  • You can find java decompilers to look into a jar file. I usually use [this one](http://java-decompiler.github.io/). – rrk Nov 08 '19 at 14:44
  • Thanks a lot @RRK. I will take a look. – Kannan.P Nov 08 '19 at 14:45
3

This is all way to much typing. While is possible you can get <cfparam, it is much easier to just use the param keyword

 param userID = 0;
 param myName = 'Kannan';
James A Mohler
  • 11,060
  • 15
  • 46
  • 72