How to specify argument attributes in CFscript? (CF9)

Asked
Viewd1190

3

In CF9 doc: Defining components and functions in CFScript, it says:

/** 
*Comment text, treated as a hint. 
*Set metadata, including, optionally, attributes, in the last entries 
*in the comment block, as follows: 
*@metadataName metadataValue 
... 
*/ 
access returnType function functionName(arg1Type arg1Name="defaultValue1" 
arg1Attribute="attributeValue...,arg2Type 
arg2Name="defaultValue2" arg2Attribute="attributeValue...,...) 
functionAttributeName="attributeValue" ... { 
body contents 
}

How do you specify arg1Attribute? I tried this:

public void function setFirstname(string firstname="" displayName="first name"){}

but it does NOT work.

Also, how do you translate this to script-style?

<cffunction name="setPerson">
  <cfargument name="person" type="com.Person"/>
</cffunction>

I tried:

function setPerson(com.Person person){}

and it does NOT work either. "You cannot use a variable reference with "." operators in this context" it says.

  • if this is a bug, pls vote: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80394

    Henry20 октября 2009, 00:11

3 ответов

1

fixed in CF9 Update 1

/** This is setPerson function hint
*  @person this is person argument hint
*/
function setPerson(com.Person person){}

This will work, but CFBuilder (as of 1.0 release) will consider this invalid still.

  • CFBuilder 1.0 will not even do syntax highlighting once you use dot for argument type… let alone intellisense

    Henry15 апреля 2010, 00:09
  • Do you get code assistance doing it this way? AKA Intellisense

    jfrobishow14 апреля 2010, 21:21
6

Turns out this is a documentation bug. There is no way to provide metadata for an argument in a script block. You can do the hint, required, type, and defaults, but nothing else. I'm asking about the com.Person thing. Mark Mandel suggested importing com and just using Person.

  • Thx. I tried importing and using Person, but that does not work either ‘cause the function will still assume the argument type is Person in the same package.

    Henry20 октября 2009, 17:39
0

I just ran into the same issue and found you can do Java style import for multiple COM with a *.

import Path.To.Your.CFC.*; 

I was able to use the plain ArgType then. You might want to make sure that "Component cache" is disabled in your CF Admin or restart your server cause I am pretty sure CF will remember not finding it.

The import even "survived" 3 level of inheritance and was available in the childcomponent.