10 Replies Latest reply: Jul 27, 2011 1:16 PM by BeerIsGood RSS

    <cfcomponent output="false">

    Owain North Community Member

      Not something I've really looked into that much before, but what does this actually do?

       

      If you do this:

       

      <cffunction output="false"> then it supresses output from the method.

       

      I would therefore expect that <cfcomponent output="false"> supresses output from the entire cfc, but it doesn't seem to. So what's the point? There doesn't seem to be anything in the docs about it (or at least not that I can find) and Googling didn't bring out much.

       

      As I'd imagine the vast majority of methods and cfcs give no output, it seems a bit odd that output="true" is the default. Anyone got any thoughts?

        • 1. Re: <cfcomponent output="false">
          Adam Cameron. Community Member

          The OUTPUT attribute of the CFCOMPONENT tag suppresses output from the "pseudo-constructor" code: code that is within the CFCOMPONENT tags, but outwith any CFFUNCTION tags.  This code is run when the CFC is instantiated.

           

          OUTPUT for CFCOMPONENT loks like it's a boolean, but it's actually tri-state:

          OUTPUT=TRUE: behaves as if the whole thing is wrapped in CFOUTPUT tags

          OUTPUT=FALSE: behaves as if the whole thign is wrapped in CFSILENT tags

          OUTPUT=[not specified] behaves like normal CFML code: will output plain text, but to resolve dynamic values (eg: stuff within hash-marks / pound-signs), one needs to use CFOUTPUT tags.

           

          I guess this is why it's not CFOUTPUT=FALSE by default.  If that was the default, then there'd be no way of reflecting that third state.

           

          If I was architecting the CFC implementation, it'd be output=false by default, and if output=true then the code would act like any normal CFML: so like the current [not specified] behaviour.  I think the way OUTPUT=TRUE behaves is stupid: who the hell would want ALL their code in CFOUTPUT tags?

           

          Does that answer your question(s)?

           

          --

          Adam

          • 2. Re: <cfcomponent output="false">
            Owain North Community Member

            I believe it does, yes. Have a "correct answer", whatever that means for anyone

             

            I'm just working on a new project so I'm trying writing all the cfcs in cfscript purely to see how well it works for me, and having to put in "output=false" statements everywhere just seems just such a waste of time and space.

             

            Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea.

             

            Ta muchly.

            • 3. Re: <cfcomponent output="false">
              Adam Cameron. Community Member

              Now... when you say you're doing them in CFScript, do you mean as per CF9's new "script-only CFCs"?  You can almost get away with not bothering with OUTPUT=FALSE in that case, as CFScript doesn't generate spurious output like tags do.

               

              The only thing to watch for is if within your script-only CFC you call a non-script CFC method which doesn't have output suppressed: then its spurious output could still bleed out.

               

              --

              Adam

              • 4. Re: <cfcomponent output="false">
                Owain North Community Member

                I am indeed going for script-only CFCs, so I guess I could do without. I'm only weary as I've been caught out so many times before by functions adding in the odd space where I don't want it to.

                 

                Worth a try I guess...

                • 5. Re: <cfcomponent output="false">
                  Dan Bracuk Community Member

                  Regarding "Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea"

                   

                  cfc's are one of the ways to produce re-useable code.  Sometimes the code you want to re-use involves outputting to a page.

                  • 6. Re: <cfcomponent output="false">
                    Owain North Community Member

                    I'm not saying you'd never want re-usable code that outputs, I'm saying why would you use a cfc for that? Surely you'd use an include file, or a custom tag?

                     

                    I'd liken a cfc to a class definition in most other languages, and it doesn't feel like the place for outputting to a page to me.

                    • 7. Re: <cfcomponent output="false">
                      Adam Cameron. Community Member

                      Yeah, but if that stuff you want to output is in the pseudo-constructor of the CFC... you're almost certainly going about things the wrong way.

                       

                      Having spent a good 5sec thinking about it, I cannot think of any situation under which I would consider doing this to be appropriate.

                       

                      --

                      Adam

                      • 8. Re: <cfcomponent output="false">
                        BKBK Community Member

                        Dan Bracuk wrote:

                         

                        Regarding "Why anyone would have code in a cfc outside a method that renders output to a page I really do have no idea"

                        cfc's are one of the ways to produce re-useable code.  Sometimes the code you want to re-use involves outputting to a page.

                        I would never say never to this. Da Vinci and Einstein had to flout convention to find new ways of doing things.

                        • 9. Re: <cfcomponent output="false">
                          Owain North Community Member
                          I would never say never to this. Da Vinci and Einstein had to flout convention to find new ways of doing things.

                           

                          Well last thing I heard Einstein was a .NET guy and Da Vinci was one of those dirty open-source fellas, so for now I'll probably continue with not seeing the point

                          • 10. Re: <cfcomponent output="false">
                            BeerIsGood

                            I believe setting output = 'false" in cfcs also helps prevent memory leaks (and heap dumps). I am not sure if CF9 does this or not as I always add the output = 'false" in the cffunction.

                             

                            Hope it helps,

                            Bill