Search code examples
coldfusioncoldfusion-9

How do I retrieve the current value of enablecfoutputonly?


We are using Coldfusion 9.

Is there a simple way to know if enablecfoutputonly has been set to true during a particular request?


Solution

  • I cannot test with CF9 right now, but in CF10 it is accessible from getPageContext() by checking the output object:

    <cfscript>
       out = getPageContext().getOut();
       // Is the cfsetting enablecfoutputonly value currently true?
       isSettingEnabled = out.getDisableCount() >  0;
       WriteOutput("isSettingEnabled="& isSettingEnabled &"<br>");
       // Is output currently allowed?
       isOuputtingEnabled = out.getDisableCount() == 0 || out.getOutputCount() > 0;
       WriteOutput("isOuputtingEnabled="& isOuputtingEnabled &"<br>");
    </cfscript>
    

    .. or using reflection:

    <cfscript>
        out = getPageContext().getOut();
        internalMethod = out.getClass().getDeclaredMethod("isOutputEnabled", []);
        internalMethod.setAccessible( true );
        isOuputtingEnabled = internalMethod.invoke( out, [] );
       // is output currently allowed?
        WriteOutput("isOuputtingEnabled="& isOuputtingEnabled);
    </cfscript>