This morning, I was fooling around with some ColdFusion GetPageContext() stuff when I happened upon a little interesting fact: GetPageContext() is template specific. Now, I know very little about Java and what the actual page requests consist of, but I had just always thought that there was one GetPageContext() object per page request. But, as it turns out, there is a different "context" object per ColdFusion template.
To demonstrate this, I am merely getting the HashCode() of the GetPageContext() on two different templates. On each of the templates, I call the HashCode() twice to demonstrate that the multiple calls on the same template have the same outcome and that calls across templates have different outcomes.
Here is the main template:
<cfoutput> <p> Main Template: </p> <p> #GetPageContext().HashCode()#<br /> #GetPageContext().HashCode()#<br /> </p> <cfinclude template="include.cfm" /> </cfoutput>
And, here is the included template:
<cfoutput> <p> Sub Template: </p> <p> #GetPageContext().HashCode()#<br /> #GetPageContext().HashCode()#<br /> </p> </cfoutput>
Running the above main template, I get the following output:
Notice that the GetPageContext() is returning a different object for each of the two different templates. Very interesting. I am sure some of you smarter fallas out there are gonna look at this and think, "D'uh, what did you think it was gonna do?" Yeah, well I am barely able to wrap my head around the massive page context object :) There is so much to here to dig through.
Want to use code from this post? Check out the license.