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

3
在CF9文档中:在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){}

但这也不起作用。它说:“您不能在此上下文中使用带“.”运算符的变量引用。”


1
如果这是一个错误,请投票:http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80394。 - Henry
3个回答

6
原来这是一份文档错误。在脚本块中无法提供参数的元数据。您可以使用提示、必需、类型和默认值,但不能使用其他内容。我正在询问关于 com.Person 的事情。Mark Mandel 建议导入 com 并只使用 Person。

谢谢。我尝试导入并使用Person,但这也不起作用,因为函数仍然会假定参数类型是同一包中的Person。 - Henry

1

在 CF9 的第一次更新中已经修复

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

这个会起作用,但是CFBuilder(截至1.0版本)仍然会认为它无效。


你这样做会得到代码辅助吗?也就是所谓的智能感知。 - jfrobishow
CFBuilder 1.0连参数类型使用点号后都无法进行语法高亮...更不用说智能感知了。 - Henry

0

我刚遇到了同样的问题,发现你可以使用*来进行多个COM的Java风格导入。

import Path.To.Your.CFC.*; 

我能够使用普通的ArgType。你可能需要确保在CF管理中禁用“组件缓存”,或重新启动服务器,因为我相信CF会记住找不到它。

即使经过3级继承,导入也仍然可用于子组件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接