Is there a way to force a writeOutput() statement ...
# lucee
d
Is there a way to force a writeOutput() statement to actually generate output if it's calling stack is inside a function with
output="false"
? I can use
getPageContext().getResponseStream().print()
to put content into the output stream, but this doesn't always place the content in correct place in the output stream (seems like Lucee builds it's own buffer so calling this can lead to content being outputted in the incorrect order.
b
No, not really
that said, if you have bufferoutput =true and you abort from within a function with output=false, you'll see all the output up to that point
nice for debugging
s
I always wondered, but never bothered to research, does output=false really do much? I traditionally NEVER specify this parameter, others working on my code would sometimes add it, I never noticed a difference.
b
Yes, it makes a difference. If you're writing code in script, only
echo()
,
writeoutput()
or
dump()
actually send content to the page output buffer, so it's not like you'd accidentally output anything.
As opposed to tags, where ALL whitespace is output
d
After some digging around in the source code, it appears the following can be used to force content into the output stream, even when output is false:
Copy code
getPageContext().getRootOut().print("Hello world!");
This is correctly adding content to the output buffer in the correct location. (I'm tagging @bdw429s just because he might find this useful.)
b
Right, that's going to "work" because you're bypassing CF entirely and writing directly to the servlet's output stream
Anything like that should come with a "here be dragons" sort of warning 🙂
d
@bdw429s I agree with what you said. However, in my case I had a closure being fed into a component that was suppressing output, so needed a way to actually add content to the body's response from within the closure. I just thought this might be useful to some others in some use cases.
b
That's interesting that the output flag was ready from the component the closure was executing in not the component the closure was declared in 🤔
d
From my testing in Lucee 5.4.3.2, it seems as if any of the parent methods have output="false" that overrides a child method in the stack that has output="true". Now this could be a bug or expected behavior, I'm not sure.
b
Prolly expected since the child basically gives its buffer to the parent for outputting. There's defo some ambiguity though