ColdFusion 9.0 Resources |
Request interfacepublic abstract interface Request Interface to a request made to a CustomTag. The interface includes methods for retrieving attributes passed to the tag (including queries) and reading global tag settings. Methods
attributeExistsDescriptionChecks whether the attribute was passed to this tag. Returns True if the attribute is available; otherwise returns False. ExampleThe following example checks whether the user passed an attribute named DESTINATION to the tag; if not, it throws an exception: if ( ! request.attributeExists("DESTINATION") ) { throw new Exception( "Missing DESTINATION parameter", "You must pass a DESTINATION parameter in " "order for this tag to work correctly." ) ; } ; debugDescriptionChecks whether the tag contains the debug attribute. Use this method to determine whether to write debug information for this request. For more information, see writeDebug. Returns True if the tag contains the debug attribute; False, otherwise. getAttributeDescriptionRetrieves the value of a passed attribute. Returns an empty string if the attribute does not exist (use attributeExists to test whether an attribute was passed to the tag). Use getAttribute(String,String) to return a default value rather than an empty string. Returns the value of the attribute passed to the tag. If no attribute of that name was passed to the tag, an empty string is returned. getAttributeListDescriptionRetrieves a list of attributes passed to the tag. To retrieve the value of one attribute, use the getAttribute method. Returns an array of strings containing the names of the attributes passed to the tag. ExampleThe following example retrieves the list of attributes, then iterates over the list, writing each attribute and its value back to the user: String[] attribs = request.getAttributeList() ; int nNumAttribs = attribs.length ; for( int i = 0; i < nNumAttribs; i++ ) { String strName = attribs[i] ; String strValue = request.getAttribute( strName ) ; response.write( strName + "=" + strValue + "<BR>" ) ; } getIntAttributeDescriptionRetrieves the value of the passed attribute as an integer. Returns -1 if the attribute does not exist. Use attributeExists to test whether an attribute was passed to the tag. Use getIntAttribute(String,int) to return a default value rather than throwing an exception or returning -1. Returns the value of the attribute passed to the tag. If no attribute of that name was passed to the tag, -1 is returned. getQueryDescriptionRetrieves the query that was passed to this tag. To pass a query to a custom tag, you use the query attribute. It should be set to the name of a query (created using the cfquery tag). The query attribute is optional and should be used only by tags that process an existing dataset. Returns the Query that was passed to the tag. If no query was passed, returns null. ExampleThe following example retrieves a query that was passed to a tag. If no query was passed, an exception is thrown: Query query = request.getQuery() ; if ( query == null ) { throw new Exception( "Missing QUERY parameter. " + "You must pass a QUERY parameter in " "order for this tag to work correctly." ) ; } getSettingDescriptionRetrieves the value of a global custom tag setting. Custom tag settings are stored in the CustomTags section of the ColdFusion Registry key. Returns the value of the custom tag setting. If no setting of that name exists, an empty string is returned. UsageAll custom tags implemented in Java share a registry key for storing settings. To avoid name conflicts, preface the names of settings with the name of your custom tag class. For example, the code below retrieves the value of a setting named VerifyAddress for a custom tag class named MyCustomTag: String strVerify = request.getSetting("MyCustomTag.VerifyAddress") ; if ( Boolean.valueOf(strVerify) ) { // Do address verification... } |