public 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.
Checks whether the attribute was passed to this tag.
Returns true
if the attribute is available, otherwise returns false
.
public boolean attributeExists(String name)
getAttribute,
getAttributeList
Parameter | Description |
---|---|
name |
Name of the attribute to check (case insensitive) |
The 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." ) ; } ;
Checks 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 otherwise returns false.
public boolean debug()
The following example checks whether the DEBUG attribute is present, and if so, it writes a brief debug message:
if ( request.debug() )
{ response.writeDebug( "debug info" ) ; }
Retrieves 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.
public String getAttribute(String name)
attributeExists,
getAttributeList,
getIntAttribute,
getAttribute
Parameter | Description |
---|---|
name |
The attribute to retrieve (case insensitive) |
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 ) ;
Retrieves a list of attributes passed to the tag. To retrieve the value of one attribute, use the getAttribute
member function.
Returns an array of strings containing the names of the attributes passed to the tag.
public String[] getAttributeList()
attributeExists, getAttributeList
The 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>" ) ; }
Retrieves 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.
public int getIntAttribute(String name)
NumberFormatException
If the attribute is not a valid number.
attributeExists, getAttributeList, getIntAttribute
Parameter | Description |
---|---|
name |
The attribute to retrieve (case insensitive) |
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) ) ;
Retrieves 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.
public Query getQuery()
The 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." ) ; }
Retrieves 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.
public String getSetting(String name)
Parameter | Description |
---|---|
name |
The name of the setting to retrieve (case insensitive) |
All 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 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... }