Response Interfacepublic abstract interface Response Interface to response generated from a CustomTag. This interface includes methods for writing output, generating queries, and setting variables in the calling page. MethodsaddQueryDescription
Adds a query to the calling template. The query can be accessed by CFML tags in the template. After calling Returns the Query that was added to the template. CategorySyntaxpublic Query addQuery(String name, String[] columns) ThrowsIllegalArgumentException - if the name parameter is not a valid CFML variable name See alsoParameters
ExampleThe following example adds a Query named 'People' to the calling template. The query has two columns ('FirstName' and 'LastName') and two rows: // Create string array with column names (also track columns indexes) String[] columns = { "FirstName", "LastName" } ;
int iFirstName = 1, iLastName = 2 ;
// Create a query which contains these columns
Query query = response.addQuery( "People", columns ) ;
// Add data to the query
int iRow = query.addRow() ;
query.setData( iRow, iFirstName, "John" ) ;
query.setData( iRow, iLastName, "Smith" ) ;
iRow = query.addRow() ;
query.setData( iRow, iFirstName, "Jane" ) ;
query.setData( iRow, iLastName, "Doe" ) ;
setVariableDescriptionSets a variable in the calling template. If the variable name specified exists in the template, its value is replaced. If it does not exist, a new variable is created. CategorySyntaxpublic void setVariable(String name, String value) Throws
Parameters
ExampleFor example, this code sets the value of a variable named 'MessageSent' based on the success of an operation performed by the custom tag: boolean bMessageSent ;
...attempt to send the message...
if ( bMessageSent == true )
{
response.setVariable( "MessageSent", "Yes" ) ;
}
else
{
response.setVariable( "MessageSent", "No" ) ;
}
writeDescriptionOutputs text back to the user. CategorySyntaxpublic void write(String output) Parameters
ExampleThe following example outputs the value of the DESTINATION attribute: response.write( "DESTINATION = " + request.getAttribute("DESTINATION") ) ;
writeDebugDescription
Writes text output into the debug stream. This text is displayed to the end-user only if the tag contains the DEBUG attribute (check for this attribute using the CategorySyntaxpublic void writeDebug(String output) See alsoParameters
ExampleThe following example checks whether the DEBUG attribute is present; if so, it writes a brief debug message: if ( request.debug() ) {
response.writeDebug( "debug info" ) ;
}
|