2 Replies Latest reply on Oct 1, 2007 9:38 PM by Warpuser

    cfajaxproxy and CFCs / init() / this / variables scope

    Warpuser
      so, i'm trying to use cfcajaxproxy. after user enters something into text box, i want it to update on the server. i'm using cfcajaxproxy to create an instance of a JS variable tied to the CFC that will do the updating of the database. however, in this CFC i have an init() method that sets the DSN and date . when i try to call it using my JS object, it seems to go through, but when i try to access that variable from another method (called from the same JS object), it says it is not defined. same thing if i use variable scope or this scope...any ideas?? thanks!
        • 1. Re: cfajaxproxy and CFCs / init() / this / variables scope
          Level 7
          In article <f95mpu$c7q$1@forums.macromedia.com>
          "Warpuser"<webforumsuser@macromedia.com> wrote:
          > so, i'm trying to use cfcajaxproxy. after user enters something
          > into text box, i want it to update on the server. i'm using
          > cfcajaxproxy to create an instance of a JS variable tied to the CFC
          > that will do the updating of the database. however, in this CFC i
          > have an init() method that sets the DSN and date . when i try to
          > call it using my JS object, it seems to go through, but when i try to
          > access that variable from another method (called from the same JS
          > object), it says it is not defined. same thing if i use variable
          > scope or this scope...any ideas?? thanks!

          When you call the CFC via cfajaxproxy, nothing is calling init().

          This is something that catches a lot of people out when they first
          start writing remote access CFCs. The remote access CFCs are
          constructed on each remote call and the method called and then the CFC
          is thrown away.

          A typical idiom in this situation is to have your application create
          and initialize your CFC and store a reference in, say, application
          scope.

          Then your remote access CFC (the one you call via cfajaxproxy)
          delegates method calls to the same named methods on the CFC in
          application scope:

          <cffunction name="doSomething" access="remote">
          <cfargument name="data"/>

          <cfreturn application.modelCFC.doSomething(arguments.data) />

          </cffunction>

          where application.modelCFC is the CFC you've created and initialized,
          passing in DSN and date.

          Hope that helps?

          Sean A Corfield
          An Architect's View -- http://corfield.org/

          --
          I'm using an evaluation license of nemo since 61 days.
          You should really try it!
          http://www.malcom-mac.com/nemo