public abstract interface Request
Interface to a request made to a CustomTag. This interface includes methods for retrieving attributes passed to the tag (including queries) and reading global tag settings.
Method Summary | ||
---|---|---|
boolean | attributeExists(String name) | Checks to see whether the attribute was passed to this tag. |
boolean | debug() |
Checks whether the tag contains the DEBUG attribute.
|
String | getAttribute(String name) | Retrieves the value of the passed attribute. |
String | getAttributeList() | Retrieves a list of all attributes passed to the tag. |
int | getIntAttribute(String name) | Retrieves the value of the passed attribute as an integer. |
int | getIntAttribute(String name, int def) | Retrieves the value of the passed attribute as an integer (returns default if the attribute does not exist or is not a valid number). |
Query | getQuery() | Retrieves the query that was passed to this tag. |
String | getSetting(String name) | Retrieves the value of a global custom tag setting. |
public boolean attributeExists(String name)
Checks to see whether the attribute was passed to this tag.
The following example checks to see if the user passed an attribute named DESTINATION to the tag and throws an exception if the attribute was not passed:
if ( ! request.attributeExists("DESTINATION") ) { throw new Exception( "Missing DESTINATION parameter", "You must pass a DESTINATION parameter in " "order for this tag to work correctly." ) ; } ;
name
-- Name of the attribute to check (case insenstive)
Returns true if the attribute is available otherwise returns false.
getAttribute, getAttributeList
public String getAttribute(String name)
Retrieves the value of the 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.
The following example retrieves an attribute named DESTINATION and writes its value back to the user:
String strDestination = request.getAttribute("DESTINATION") ; response.write( "The destination is: " + strDestination ) ;
name
-- The attribute to retrieve (case insensitive)
The value of the attribute passed to the tag. If no attribute of that name was passed to the tag then an empty string is returned.
attributeExists, getAttributeList, getAttribute(String,String), getIntAttribute
public int getIntAttribute(String name) throws NumberFormatExceptionRetrieves the value of the passed attribute as an integer. Returns -1 if the attribute does not exist. Throws a NumberFormatException if the attribute is not a valid number. 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.
The following example retrieves an attribute named PORT and writes its value back to the user:
int nPort = request.getIntAttribute("PORT") ; if ( nPort != -1 ) response.write( "The port is: " + String.valueOf(nPort) ) ;
name
-- The attribute to retrieve (case insensitive)
The value of the attribute passed to the tag. If no attribute of that name was passed to the tag then -1 is returned.
NumberFormatException
-- If the attribute is not a valid number.
attributeExists, getAttributeList, getIntAttribute(String,int)
public String[] getAttributeList()
Retrieves a list of all attributes passed to the tag. To retrieve the value of an individual attribute you should use the getAttribute member function.
The following example retrieves the list of attributes and 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>" ) ; }
An array of strings containing the names of the attributes passed to the tag.
attributeExists, getAttribute
public Query getQuery()
Retrieves the query that was passed to this tag.
To pass a query to a custom tag you use the QUERY attribute. This attribute should be set to the name of an existing query (e.g. created using the CFQUERY tag). The QUERY attribute is optional and should only be used by tags which need to process an existing dataset.
The following example retrieves the query which was passed to the tag. If no query was passed then 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." ) ; }
The Query that was passed to the tag. If no query was passed to the tag then null is returned.
public String getSetting(String name)
Retrieves the value of a global custom tag setting. Custom tag settings are stored within the CustomTags section of the ColdFusion Registry key.
Note | All custom tags implemented in Java share a single registry key for
storing settings. This means that to avoid name conflicts you should
preface the names of your settings with the name of your
CustomTag class. For example, the code below retrieves the value of a setting named 'VerifyAddress' for a CustomTag class named MyCustomTag: |
String strVerify = request.getSetting("MyCustomTag.VerifyAddress") ; if ( Boolean.valueOf(strVerify) ) { // Do address verification... }
name
-- The name of the setting to retrieve (case insensitive)
The value of the custom tag setting. If no setting of that name exists then an empty string is returned.
public boolean debug()
Checks whether the tag contains the DEBUG attribute. You should use this method to determine whether or not you need to write debug information for this request (see Response.writeDebug for details on writing debug information).
The following example checks to see whether the DEBUG attribute is present, and if it is then it writes a brief debug message:
if ( request.debug() ) { response.writeDebug( "debug info" ) ; }
Returns true if the tag contains the DEBUG attribute otherwise returns false.
Response.writeDebug