Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at the jQuery Conference 2010 (Boston, MA) with:

I Don't Understand ColdFusion GetPageContext() And Include()

By Ben Nadel on
Tags: ColdFusion

I was pulling my hair out trying to figure out an error I was getting with the following code:

  • <!--- Include public style sheet. --->
  • <cfset GetPageContext().Include( "../../../linked/css/main.css" ) />

This line of code kept throwing the error:

java.io.FileNotFoundException

After literally an hour and a half of playing around with "../" combinations and outputting FileExists() results, I switched over to using a CFInclude tag:

  • <!--- Include public style sheet. --->
  • <cfinclude template="../../../linked/css/main.css" />

For some reason, this include works, and the include method of the GetPageContext() servlet does NOT work. I have no idea what this means. As I am not a professional Java programmer, I am not familiar with servlets and context objects. I don't know if it has something to do with web-visibility. I know that the include above were crossing over a virtual directory (an admin area was pulling the CSS file from the public site and the admin was in a virtual directory).

Who knows. I tried to Google some information about page context and I came up with this Java class, but that doesn't really help me understand. Maybe someone out there can help.

As part of my mentality, I was doing it this way so that the main.css file would be included without being parsed. As far as I know, a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file). I had no need to parse the file and was told that the Include() method would not do so.


Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader Comments

"a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file)"

It doesn't unless it's a file with an extension that equates to a Coldfusion template i.e .cfm.

Try it yourself, cfinclude a css file. If CF was trying to parse the file you'd get errors being thrown when it encounters # symbols on styling blocks.

Reply to this Comment

James,

Please take a look at the demo that I have set up. I think you are confused about evaluation of # signs vs. parsing of page looking for ColdFusion tags.

http://bennadel.com/index.cfm?dax=blog:250.view

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.