DefaultTemplateMap class
When you generate JSPs with Netscape Application Builder (NAB), the resulting JSPs use declarative tags, which support a result-set-oriented view of data rather than a bean-oriented view. To support the result-set-oriented view of request data and session data, NAS provides the DefaultTemplateMap class.
DefaultTemplateMap is a declarative-tag-aware extension to the TemplateMapBasic class. Use the methods of DefaultTemplateMap in any JSP you have generated with NAB.
The DefaultTemplateMap class represents the default implementation of an ITemplateMap object created by BaseUtils.initRowSets( ). The call to BaseUtils.initRowSets( ) creates an object that serves as the ITemplateMap in the JSP template engine.
The DefaultTemplateMap class provides a set of "virtual" ResultSets: valIn, valOut, session, and security. These four variables contain data that corresponds to values of the request attributes.
For example, the following sets of tags are identical:
Package
com.netscape.server.servlet.extension
Constructor
The following constructor is required:
public DefaultTemplateMap(
HttpServletRequest request,
HttpServletResponse response)
The parameters represent the request and response objects.
Related Topics
TemplateMapBasic class
Methods
doesResultSetExist( )
Determines whether a result set exists.
Syntax
public String doesResultSetExist(
NASString key)
key.
The result set to check for.
Usage
Use doesResultSetExist( ) to determine whether a result set exists.
Return Value
Returns null if the specified result set exists in the request attribute set; otherwise returns "", the null string.
Example
The following code calls doesResultSetExist( ) from within a gx tag:
<gx type=cell id=doesResultSetExist(foo)>
Do something here; for example, dereference the result set
</gx>
To achieve the same effect without using doesResultSetExist( ), you could use the following code instead.
<% Object foo = request.getAttribute("foo");
if ( foo != null && foo instanceof ResultSet )
{
%>
Do something here; for example, dereference the result set
<% } %>
getBuffer( )
Resolves the id attribute specified in a GX markup tag in the template being processed by the JSP.
Syntax 1
This form is called to verify that the named tag is neither a reference to the virtual ResultSet (such as valIn) nor a reference to a method call (such as doesResultSetExist). If verification succeeds, the second method form is called. If verification fails (meaning that the named tag is, in fact, a reference to a virtual ResultSet or to a method call), then the value is computed and returned.
public IBuffer getBuffer(
String name,
IObject pData,
IObject pMark)
Syntax 2
This form is called after the previous form of getBuffer( ) succeeds with its verifications.
public IBuffer getBuffer(
NASString name,
IObject pData,
IObject pMark)
name.
The field name of the id attribute in the current GX markup tag.
pData.
Specify null. Internal use only.
pMark.
Specify null. Internal use only.
Usage
Typically, developers never call this method explicitly. The JSP calls getBuffer( ) to resolve the id attribute specified in a GX markup tag in the template being processed by the JSP. To provide application-specific processing, a servlet can subclass the TemplateMapBasic class and override getBuffer( ) to manipulate the JSP-generation process. For example, a servlet can intercept and filter data from a database before the JSP processes it.
Syntax 1 of getBuffer( ), which takes a String parameter, should not be overridden. This form supports virtual ResultSets and user-defined method calls. See getStaticMethodCache( ) for more information.
Syntax 2 of getBuffer( ) should be overridden instead.
Return Value
An IBuffer object that contains the value of the id mapping, or null for failure.
Related Topics
ITemplateData interface (deprecated)
TemplateDataBasic class (deprecated)
getStaticMethodCache( )
Returns a method cache.
Syntax
public MethodHash getStaticMethodCache()
Usage
getStaticMethodCache( ), which is intended to be overridden for caching, returns a method cache that is stored statically on a class.
This method returns either its method cache or null. getStaticMethodCache( ) must return its method cache only when this method is called on an object of the same class in which the method is defined.
If the classes are different, the server might cache methods on Java classes that are no longer in use and that should be garbage-collected. In this case, the method returns null instead.
If you create subclasses of DefaultTemplateMap, you must provide an implementation of getStaticMethodCache( ), so that caching occurs for method-lookups against your subclass.
Return Value
A MethodHash object representing a method cache, or null for failure.
Related Topics
createMethodHash( ) in the BaseUtils class
getString( )
Resolves the id attribute in a GX markup tag.
Syntax 1
public String getString(
String name,
IObject pData,
IObject pMark)
Syntax 2
public String getString(
NASString name,
IObject pData,
IObject pMark)
name.
The field name of the id attribute in the current GX markup tag.
pData.
Specify null. Internal use only.
pMark.
Specify null. Internal use only.
Usage
The getString( ) and getBuffer( ) methods are identical, except that getString( ) returns a String rather than an IBuffer object.
isEqualToExpression( )
Evaluates a field specification in an HTML template.
Syntax
public String isEqualToExpression(
NASString expression)
expression.
The expression to evaluate.
Usage
This method is similar to isEqualToValue( ). Both methods are intended to be called from the template engine, with the expression containing one equal sign (=) and the lefthand value being a full field specification. However, in isEqualToValue( ) the righthand value is a constant, whereas in isEqualToExpression( ), the righthand value is another field specification.
The isEqualtoValue( ) method lets you write more standard if statements in an HTML template. The isEqualToExpression( ) method is useful for filling a popup list.
Example
The following code fragment creates a data set as a list:
MemRowSet ds = new MemRowSet();
ds.setRequest(request);
ds.setResponse(response);
ds.setName("myList");
ds.addListItem("Star Trek", "1");
ds.addListItem("Babylon 5", "2");
ds.addListItem("Red Dwarf", "3");
ds.addListItem("Crusade", "4");
request.setAttribute(ds.getName(), ds);
To display this list on a web page, you might create an HTML template containing the following code:
<SELECT NAME="TVShow">
%gx type=tile id=myList%
<OPTION VALUE="%gx type=cell id=myList.value% %/gx%"
%gx
type=cell
id=myList.isEqualToExpression(
myList.value=valIn.foo)%SELECTED
%/gx%
>
%gx type=cell id=myList.label%%/gx%
%/gx%
</SELECT>
Return Value
A String value representing, for example, the ID of a gx tag in an HTML template.
Related Topics
isEqualToValue( )
isEqualToValue( )
Evaluates a field specification in an HTML template.
Syntax
public String isEqualToExpression(
NASString expression)
expression.
The expression to evaluate.
Usage
This method is similar to isEqualToExpression( ). Both methods are intended to be called from the template engine, with the expression containing one equal sign (=) and the lefthand value being a full field specification. However, in isEqualToValue( ) the righthand value is a constant, whereas in isEqualToExpression( ), the righthand value is another field specification.
The isEqualtoValue( ) method lets you write more standard if statements in an HTML template. The isEqualToExpression( ) method is useful for filling a popup list.
For example, you can use isEqualToValue( ) to determine whether a checkbox should be "CHECKED" or not.
Example
<gx type=cell id=isEqualToValue(session.field_name=ALLMINE)>
HTML specific to ALLMINE
</gx>
Return Value
A String value representing, for example, the ID of a gx tag in an HTML template.
Related Topics
isEqualToExpression( )
|