Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Modifying application variables

Explorer ,
Sep 12, 2008 Sep 12, 2008
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?
671
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2008 Sep 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 12, 2008
You have to change back to the original application. Once you run a
<cfapplication ...> your code is completely inside the new application,
if you need to access the original you will need to run another
<cfapplication...> to re-connect to the original.

<cfapplication name="first"...>
Do stuff in the first application

<cfapplication name="second"...>
Do stuff in the second application.

<cfapplication name="first...>
Do stuff in the first application again.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2008 Sep 12, 2008
Yes, I've got that set up already. Thanks for following up on that last point. This is very useful. Thank you again!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 12, 2008 Sep 12, 2008
LATEST
> 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources