ColdFusion 9.0 Resources |
CCFXRequest classContents [Hide]Abstract class that represents a request made to a ColdFusion Extension (CFX). An instance of this class is passed to the main function of your extension DLL. The class provides interfaces that can be used by the custom extension for the following actions:
Class methods
CCFXRequest::AddQueryDescriptionAdds a query to the calling template. The query can be accessed by CFML tags (for example, cfoutput or cftable) within the template. After calling AddQuery, the query is empty (it has 0 rows). To populate the query with data, call the CCFXQuery::AddRow and CCFXQuery::SetData functions. ReturnsReturns a pointer to the query that was added to the template (an object of class CCFXQuery). The memory allocated for the returned query is freed automatically by ColdFusion after the request is completed. Parameters
ExampleThe following example adds a query named 'People' to the calling template. The query has two columns ('FirstName' and 'LastName') and two rows: // Create a string set and add the column names to it CCFXStringSet* pColumns = pRequest->CreateStringSet() ; int iFirstName = pColumns->AddString( "FirstName" ) ; int iLastName = pColumns->AddString( "LastName" ) ; // Create a query that contains these columns CCFXQuery* pQuery = pRequest->AddQuery( "People", pColumns ) ; // Add data to the query int iRow ; iRow = pQuery->AddRow() ; pQuery->SetData( iRow, iFirstName, "John" ) ; pQuery->SetData( iRow, iLastName, "Smith" ) ; iRow = pQuery->AddRow() ; pQuery->SetData( iRow, iFirstName, "Jane" ) ; pQuery->SetData( iRow, iLastName, "Doe" ) ; CCFXRequest::AttributeExistsDescriptionChecks whether the parameter was passed to the tag. Returns True if the parameter is available; False, otherwise. ExampleThe following example checks whether the user passed an attribute named DESTINATION to the tag, and throws an exception if the attribute was not passed: if ( pRequest->AttributeExists("DESTINATION")==FALSE ) { pRequest->ThrowException( "Missing DESTINATION parameter", "You must pass a DESTINATION parameter in " "order for this tag to work correctly." ) ; } CCFXRequest::CreateStringSetDescriptionAllocates and returns an instance. Always use this function to create string sets, as opposed to directly using the new operator. ReturnsReturns an object of CCFXStringSet class. The memory allocated for the returned string set is freed automatically by ColdFusion after the request is completed CCFXRequest::DebugDescriptionChecks whether the tag contains the Debug attribute. Use this function to determine whether to write debug information for a request. For more information, see CCFXRequest::WriteDebug. CCFXRequest::GetAttributeDescriptionRetrieves the value of the passed attribute. Returns an empty string if the attribute does not exist. (To test whether an attribute was passed to the tag, use CCFXRequest::AttributeExists.) CCFXRequest::GetAttributeListDescriptionGets an array of attribute names passed to the tag. To get the value of one attribute, use CCFXRequest::GetAttribute. ReturnsReturns an object of class CCFXStringSet class that contains a list of attributes passed to the tag. The memory allocated for the returned string set is freed automatically by ColdFusion after the request is completed. ExampleThe following example gets the list of attributes and iterates over the list, writing each attribute and its value back to the user. LPCSTR lpszName, lpszValue ; CCFXStringSet* pAttribs = pRequest->GetAttributeList() ; int nNumAttribs = pAttribs->GetCount() ; for( int i=1; i<=nNumAttribs; i++ ) { lpszName = pAttribs->GetString( i ) ; lpszValue = pRequest->GetAttribute( lpszName ) ; pRequest->Write( lpszName ) ; pRequest->Write( " = " ) ; pRequest->Write( lpszValue ) ; pRequest->Write( "<BR>" ) ; } CCFXRequest::GetCustomDataDescriptionGets the custom (tag specific) data for the request. This method is typically used from within subroutines of a tag implementation to extract tag data from a request. ReturnsReturns a pointer to the custom data, or NULL if no custom data has been set during this request using CCFXRequest::SetCustomData. CCFXRequest::GetQueryDescriptionRetrieves a query that was passed to a tag. To pass a query to a custom tag, you use the QUERY attribute. Set the attribute to the name of a query (created using the cfquery tag or another custom tag). The QUERY attribute is optional and must be used only by tags that process an existing data set. ReturnsReturns an object of the CCFXQuery class that represents the query passed to the tag. If no query was passed to the tag, NULL is returned. The memory allocated for the returned query is freed automatically by ColdFusion after the request is completed. ExampleThe following example retrieves the query that was passed to the tag. If no query was passed, an exception is thrown: CCFXQuery* pQuery = pRequest->GetQuery() ; if ( pQuery == NULL ) { pRequest->ThrowException( "Missing QUERY parameter", "You must pass a QUERY parameter in " "order for this tag to work correctly." ) ; } CCFXRequest::ReThrowExceptionDescriptionRethrows an exception that has been caught within an extension procedure. This function is used to avoid having C++ exceptions that are thrown by DLL extension code propagate back into ColdFusion. Catch ALL C++ exceptions that occur in extension code, and either re-throw them (if they are of the CCFXException class) or create and throw a new exception pointer using CCFXRequest::ThrowException. ExampleThe following code demonstrates how to handle exceptions in ColdFusion Extension DLL procedures: try { ...Code that could throw an exception... } catch( CCFXException* e ) { ...Do appropriate resource cleanup here... // Re-throw the exception pRequest->ReThrowException( e ) ; } catch( ... ) { // Something nasty happened pRequest->ThrowException( "Unexpected error occurred in CFX tag", "" ) ; } CCFXRequest::SetCustomDataDescriptionSets custom (tag specific) data to carry with the request. Use this function to store request specific data to pass to procedures within your custom tag implementation. ExampleThe following example creates a request-specific data structure of hypothetical type MYTAGDATA and stores a pointer to the structure in the request for future use: void ProcessTagRequest( CCFXRequest* pRequest ) try { MYTAGDATA tagData ; pRequest->SetCustomData( (LPVOID)&tagData ) ; ... remainder of procedure ... } CCFXRequest::SetVariableDescriptionSets a variable in the calling template. If the variable name already exists in the template, its value is replaced. If it does not exist, a variable is created. The values of variables created using SetVariable can be accessed in the same manner as other template variables (for example, #MessageSent#). ExampleThe following example sets the value of a variable named 'MessageSent' based on the success of an operation performed by the custom tag: BOOL bMessageSent; ...attempt to send the message... if ( bMessageSent == TRUE ) { pRequest->SetVariable( "MessageSent", "Yes" ) ; } else { pRequest->SetVariable( "MessageSent", "No" ) ; } CCFXRequest::ThrowExceptionDescriptionThrows an exception and ends processing of a request. Call this function when you encounter an error that does not allow you to continue processing the request. This function is almost always combined with the CCFXRequest::ReThrowException to protect against resource leaks in extension code. Parameters
ExampleThe following example throws an exception indicating that an unexpected error occurred while processing a request: char buffError[512] ; wsprintf( buffError, "Unexpected Windows NT error number %ld " "occurred while processing request.", GetLastError() ) ; pRequest->ThrowException( "Error occurred", buffError ) ; CCFXRequest::WriteDebugDescriptionWrites text output into the debug stream. The text is only displayed to the end user if the tag contains the Debug attribute. (For more information, see CCFXRequest::Debug.) |