【问题标题】:Extending mail object in a cfc在 cfc 中扩展邮件对象
【发布时间】:2015-12-15 17:41:33
【问题描述】:

我在 cfscript 中使用 mail() 对象。我想扩展该对象,以便覆盖 setTo() 方法。这是我写的cfc代码。

component extends="com.adobe.coldfusion.mail"
{
  public void function setTo(String recipients) {
    machineName = createObject("java", "java.net.InetAddress").localhost.getCanonicalHostName();

    if (FindNoCase("devcomputer", machinename) == 0) 
    {
      super.setTo(arguments.recipients);
    }
    else
    {
      super.setTo(this.getFrom());
    }       
  } 
}

但是,当它运行时,我收到一条消息说 setTo() 方法在调用 super.setTo() 的行中不存在。进一步挖掘,我查看了超级对象,它继承自 java.lang.Class,而不是 com.adobe.coldfusion.email。

扩展 ColdFusion 的邮件对象以便我可以覆盖 setTo() 方法的正确方法是什么?

【问题讨论】:

    标签: coldfusion coldfusion-11 cfmail


    【解决方案1】:

    com.adobe.coldfusion.mail 中的 getter/setter 实际上不是函数,而是访问器。访问器由 ColdFusion 根据组件中的属性自动生成。 属性是继承的,访问者不是!

    邮件组件中的访问器只会设置/获取属性的值。 super.setTo(arguments.recipients); 的等价物因此是 variables.to = arguments.recipients;this.getTo() 的等价物是 variables.to 等。

    注意:将accessors="true"extends="com.adobe.coldfusion.mail" 的组件一起使用也不适用于继承的属性。

    【讨论】:

    • 属性是继承的,访问器不是.. ~_~ 看起来像一个错误不是吗?
    • 取决于视角,我猜。之所以这样设计是有原因的。好吧,我不建议一开始就使用(cf)property,但这只是我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    相关资源
    最近更新 更多