2012-07-06 42 views
2

我一直致力于ColdFusion中的Braintree集成。 Braintree不直接支持CF,但他们提供了一个Java库,我迄今为止所做的所有工作都非常成功......直到现在。看起来某些对象(特别是搜索功能)具有无法从CF访问的方法,我怀疑这是因为它们是CF保留字,如“is”和“contains”。有什么办法可以解决这个问题吗?具有CF保留字的方法名称的Java cfObject

<cfscript> 
gate = createObject("java", "com.braintreegateway.BraintreeGateway").init(env,merchant.getMerchantAccountId(), merchant.getMerchantAccountPublicSecret(),merchant.getMerchantAccountPrivateSecret()); 
req = createObject("java","com.braintreegateway.CustomerSearchRequest").id().is("#user.getUserId()#"); 
customer = gate.customer().search(req); 
</cfscript> 

抛出的错误:无效CFML构建... ColdFusion的看着下面的文字:是

+0

您是否尝试过''? – Henry 2012-07-06 05:28:24

回答

6

这代表CF编译器中的一个错误。在CF中没有规定无法定义称为is()this()的方法,而且在基本情况下调用它们也没有问题。此代码演示:

<!--- Junk.cfc ---> 
<cfcomponent> 
    <cffunction name="is"> 
     <cfreturn true> 
    </cffunction> 
    <cffunction name="contains"> 
     <cfreturn true> 
    </cffunction> 
</cfcomponent> 

<!--- test.cfm ---> 
<cfset o = new Junk()> 

<cfoutput> 
    #o.is()#<br /> 
    #o.contains()#<br /> 
</cfoutput> 

这 - 不出所料 - 输出:

true 
true 

然而,我们有问题,如果我们引入一个init()方法来Junk.cfc,从而:

<cffunction name="init"> 
    <cfreturn this> 
</cffunction> 

然后相应地调整test.cfm:

#o.init().is()#<br /> 
#o.init().contains()#<br /> 

这将导致一个编译器错误:

Invalid CFML construct found on line 4 at column 19.

ColdFusion was looking at the following text:

is

[...]

coldfusion.compiler.ParseException: Invalid CFML construct found on line 4 at column 19.

at coldfusion.compiler.cfml40.generateParseException(cfml40.java:12135) 

[etc]

没有正当的理由,为什么o.init().is()不应该是确定的,如果o.is()是好的。

我建议你file a bug。我会为此投票。

作为解决方法如果您使用中间值而不是方法链接,则应该没问题。

+0

伟大的解释 - 爱它! – 2012-07-06 12:17:46

+0

错误3231457申请 – 2012-07-06 14:19:33

+0

直接链接到3231457:https://bugbase.adobe.com/index.cfm?event=bug&id=3231457 – 2012-07-06 14:48:19

1

你或许可以使用Java Reflection API调用的是()方法的对象。

我还养与Adobe的调用,看看他们会解决它,或提供自己的解决方法。我可以理解,不允许定义自己的方法或称为'is'的变量,但试图在这里调用它应该是安全的。

0

下面是解决这个问题的方法。至少有一个修复,让你启动和运行。

试试看看这个代码。

<cfscript> 
    //Get our credentials here, this is a custom private function I have, so your mileage may vary 
    credentials = getCredentials(); 

    //Supply the credentials for the gateway  
    gateway = createObject("java", "com.braintreegateway.BraintreeGateway").init(credentials.type, credentials.merchantId, credentials.publicKey, credentials.privateKey); 

    //Setup the customer search object 
    customerSearch = createObject("java", "com.braintreegateway.CustomerSearchRequest").id(); 

    //can't chain the methods here for the contains, since it's a reserved word in cf. lame. 
    customerSearchRequest = customerSearch.contains(arguments.customerId); 

    //Build the result here 
    result = gateway.customer().search(customerSearchRequest); 
</cfscript> 
相关问题