Skip to main content
Inspiring
October 24, 2012
Answered

Stumped - Variable exists, then does not.

  • October 24, 2012
  • 3 replies
  • 13665 views

Whew!  This is a new one on me!  One of those times CF simply isn't making any logical sense to how I understand it.  I've even gone through CF10 Application Server and IIS Admin service restarts and still getting the same problem.

In short, I have a template component which has a variable called rawCode.  It is the current request's generated HTML that is to be output to the buffer.  I am inside a method inside the template component, and I dump: THIS.rawCode.

Sure enough, it contains what I expect.

I then call a method from within this method (that method exists in the template component as well)

<cfinvoke component="#THIS#" method="writeOutputToBuffer">

All that method does right now is:

<cfoutput>#THIS.rawOutput#</cfoutput>

But guess what?  At that point, there's nothing!  Nothing is presented to the user.  I had it dump THIS.rawCode and BOOM, the rawCode is there and populated with what I wante returned to the user.  Has anyone seen something like this before?  I'm sure there's some rare thing I'm doing wrong here, like some recently unknown "CF10 can only support referencing a variable 20 times per request" rule or something as crazy.

    This topic has been closed for replies.
    Correct answer 12Robots

    Scrap some of that.

    It seems after I call the writeOutputToBuffer() method and return back to the generateRequestContent() method, outputing or dumping the THIS.rawCode results in NOTHING being there.  The variable just seems to empty out somewhere.


    Does writeOutputToBuffer() have output="true"?

    Jason

    3 replies

    Inspiring
    October 24, 2012

    Dunno.  But two things.

    1. If you're within the same CFC, you don't need to specify the COMPONENT attribute of the <cfinvoke> tag.  Perhaps because you are passing it THIS, it's doing something other than you expect?  Not sure.
    2. For pity's sake, don't use <cfinvoke>.  Just go <cfset writeOutputToBuffer()>

    --

    Adam

    Inspiring
    October 24, 2012

    @12Robots—

    Man, it's such an extensive setup I have.  I'll try to provide some code without giving all the exta.

    By default, the code is created in the template.cfc's pseudo constructor:

    <cfparam name="THIS.rawCode" type="string" default="">

    In the onRequest(), we create an instances of the template component by doing the following: (this component extends the root application.cfc)

    <cfset REQUEST.template = createObject( 'component', 'www.app.coms.template' )>

    We then call a method in the REQUEST.template component to start creating the output code:

    <cfinvoke component="#REQUEST.template#" method="generateRequestOutput">

    It goes through many steps, populating the THIS.rawCode with content until we get to the very end of the generateRequestOutput() method.  There are 2 closing functions:

    processTemplateVars() - Before AND after this method is called, we can dump THIS.rawCode and we see what we expect.  The last function,

    writeOutputToBuffer() - When I do the dump of THIS.rawCode in that function, I get nothing.  But when it returns back to the generateRequestOutput() after the writeOutputToBuffer(), and I dump it, it DOES exist.

    That's where I'm confused.

    @Adam Cameron—

    1. Cool; didn't know that.  CF must assume a local invoke when the component is not specified.  I'll try to remove that.

    2. Really?  I love how you can use argument names as attributes in a <CFINVOKE>.  I hate writing like writeOutputToBuffer( arg1, arg2, arg3 ).

    Inspiring
    October 24, 2012

    Scrap some of that.

    It seems after I call the writeOutputToBuffer() method and return back to the generateRequestContent() method, outputing or dumping the THIS.rawCode results in NOTHING being there.  The variable just seems to empty out somewhere.

    12Robots
    Participating Frequently
    October 24, 2012

    Show us more code. What does this "template component" look like?  How does it get populated with the "rawCode". How are you invoking the Component? 

    Jason

    Carl Von Stetten
    Legend
    October 24, 2012

    You say "THIS.rawCode" at the top of your post, but refer to "THIS.rawOutput" in the method call.

    -Carl V.

    Inspiring
    October 24, 2012

    Good catch.  Sorry, they all say the same thing.  'THIS.rawCode'.  Sorry 'bout that.