Skip to main content
Participating Frequently
September 12, 2008
Question

Modifying application variables

  • September 12, 2008
  • 4 replies
  • 713 views
I have multiple applications running under a single instance of CF server 8 on a J2EE box and am looking for a way to modify application scope data in one (or more) of the application(s) from within a different application (this application is a management area). Is this possible? If so, how would I reference the application scopes of each app from the outside?
    This topic has been closed for replies.

    4 replies

    Inspiring
    September 12, 2008
    > I know that normally ColdFusion passes complex variables by reference.
    > How would this work within our multiple <application...> scenario?
    >
    > I.E. Some ruff code to give an idea of where I am going with this.
    >
    > <cfapplication name="one"...>
    > <cfset variables.appOne = application>
    >
    > <cfapplication name="two"...>
    > <cfset variables.appTwo = application>
    >
    > <cfdump var="#variables.appOne#">
    > <cfdump var="#variables.appTwo#">
    >
    > <cfset variables.appOne.something = variables.appTwo.somethingElse>

    Yep, that works: have done it before, indeed for the very purpose the OP is
    needing it for.

    --
    Adam
    Inspiring
    September 12, 2008
    Adam Cameron wrote:
    >
    > This got me thinking.
    >

    That is a interesting piece of code Adam and I will file it way for
    further playing when I have some spare time.

    I had another idea that I don't have time to test right now, but I will
    throw it out there for somebody who may. Or maybe somebody already
    knows how this would work.

    I know that normally ColdFusion passes complex variables by reference.
    How would this work within our multiple <application...> scenario?

    I.E. Some ruff code to give an idea of where I am going with this.

    <cfapplication name="one"...>
    <cfset variables.appOne = application>

    <cfapplication name="two"...>
    <cfset variables.appTwo = application>

    <cfdump var="#variables.appOne#">
    <cfdump var="#variables.appTwo#">

    <cfset variables.appOne.something = variables.appTwo.somethingElse>

    etc.


    Inspiring
    September 12, 2008
    >> Is this possible? If so, how would I
    >> reference the application scopes of each app from the outside?

    > No it is not possible. You can not modify application scope from
    > outside a given application.

    This got me thinking.

    And 30min of fiddling about yielded this proof-of-concept code:

    {code}
    <cfapplication name="test1">
    <cfset application.test1.key = "value1">
    <cfapplication name="test2">
    <cfset application.test2.key = "value2">

    <cfset oAppScopeTracker = createObject("java",
    "coldfusion.runtime.ApplicationScopeTracker").init()>
    <cfset stTemp = oAppScopeTracker.getApplicationScope('test1')>
    <cfdump var="#stTemp#">
    <cfset stTemp = oAppScopeTracker.getApplicationScope('test2')>
    <cfdump var="#stTemp#">
    <cfset stTemp.test2.key = "updated">
    <cfset stTemp = oAppScopeTracker.getApplicationScope('test2')>
    <cfdump var="#stTemp#">
    {code}

    I didn't know one could do that until now.

    --
    Adam
    Inspiring
    September 12, 2008
    gammajack wrote:
    > Is this possible? If so, how would I
    > reference the application scopes of each app from the outside?
    >

    No it is not possible. You can not modify application scope from
    outside a given application.

    However:

    You can jump in and out of different applications at any time in the
    same template file by just including multiple <cfapplicaiton...> tags.

    I.E.
    my_management_app.cfm
    ---------
    <h1>A bunch of application data</h1>

    <cfapplication name="FooBar"...>
    <h2>Foobar App</h2>
    <cfdump var="#application#">

    <cfapplication name="George"...>
    <h2>George App</h2>
    <cfdump var="#application#">

    <cfapplication name="Gracie"...>
    <h2>Gracie App</h2>
    <cfdump var="#application#">

    etc.


    Participating Frequently
    September 12, 2008
    Using your recommended code to jump around to different applications, I was able to create new application variables and change their values in one application from within a different one. I was not, however, able to change values for application variables that were already created and present in that application.

    Thanks for the info. I appreciate it.