Interceptor Output Buffer
Every interception point receives a unique request output buffer that can be used to elegantly produce output. Once the interception point is executed, the interceptor service will check to see if the output buffer has content, if it does it will advice to write the output to the ColdFusion output stream. This way, you can produce output very cleanly from your interception points, without adding any messy-encapsulation breaking output=true tags to your interceptors. (BAD PRACTICE). This is an elegant solution that can work for both core and custom interception points.
1
// Using methods, meaning you inherited from Interceptor or registered at configuration time.
2
function preRender( event, data, buffer, rc, prc ){
3
//clear all of it first, just in case.
4
arguments.buffer.clear();
5
//Append to buffer
6
arguments.buffer.append( '<h1>This software is copyright by Funky Joe!</h1>' );
7
}
Copied!
Hint Each execution point will have its own clean buffer to work with. As each interception point has finalized execution, the output buffer is flushed, only if content exists.

Output Buffer Argument

Here are some examples using the buffer argument:
1
function onSidebar( event, data, buffer, rc, prc ){
2
savecontent variable="local.data"{
3
/// HTML HERE
4
}
5
6
arguments.buffer.append( local.data );
7
}
8
9
// using argument
10
function preRender( event, data, buffer, rc, prc ){
11
//clear all of it first, just in case.
12
arguments.buffer.clear();
13
//Append to buffer
14
arguments.buffer.append('<h1>This software is copyright by Funky Joe!</h1>');
15
}
Copied!
Here are some common methods on the buffer object:
    append( str ) Append strings to the buffer
    clear() Clear the entire buffer
    length() Get size of the buffer
    getString() Get the entire string in the buffer
    getBufferObject() Get the actual java String Builder object
Last modified 1yr ago
Copy link