如何在CFscript中指定参数属性? (CF9)

时间:2009-10-19 23:34:21

标签: coldfusion

在CF9 doc:Defining components and functions in CFScript中,它说:

/** 
*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 
}

如何指定arg1Attribute?我试过这个:

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

但它不起作用。

另外,你如何将其翻译成脚本风格?

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

我试过了:

function setPerson(com.Person person){}

它也不起作用。 “你不能在这个上下文中使用带有”。“运算符的变量引用”它说。

3 个答案:

答案 0 :(得分:6)

原来这是一个文档错误。无法为脚本块中的参数提供元数据。您可以执行提示,必需,类型和默认值,但不能执行任何其他操作。我在询问com.Person的事情。 Mark Mandel建议导入com并使用Person。

答案 1 :(得分:1)

已在CF9 Update 1中修复

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

这样可行,但CFBuilder(1.0版本)将认为此无效。

答案 2 :(得分:0)

我刚遇到同样的问题,发现你可以用*。

为多个COM做Java样式导入
import Path.To.Your.CFC.*; 

然后我可以使用普通的ArgType。您可能希望确保在CF管理员中禁用“组件缓存”或重新启动服务器,因为我非常确定CF会记住找不到它。

导入甚至“幸存”了3级继承,并且在子组件中可用。