JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»

■    If the operand starts with a “#,” then following the “#” is an integer value, and the second operand should be an Integer object that was created from this value.

■    If the operand starts with a “$,” then following the “$” is the name of a JSP scripting variable (some Java object) whose value should be used as the second operand.

■    If the operand does not start with “$” or “#” it is a plain string value.

These three rules make the second operand very flexible, yet keep things simple for the JSP developer.

All our binary operators implement the same Operator interface. This way we can handle many different operators the same way.

In a nutshell TestTag’s job is to evaluate its condition and, based on the result, to embed (or not) its body content in the response. This is accomplished relatively simply because o
f the work partition between WithTag and TestTag.


We saw that TestTag created a framework where we can plug additional operators as needed. With all these operators, you might expect the TagExtraInfo associated with TestTag to be huge. Will we have to change it whenever we add a new operator? If so, this entire flexible operator framework does not seem to be worth all that 
much. The answer to these concerns is in listing 9.6 where you see the implementation of TestTagExtraInfo.

Listing 9.6 Source code for the TestTagExtraInfo class

package book.conditions;

import javax.servlet.jsp.tagext.TagData; import javax.servlet.jsp.tagext.TagExtraInfo;

import book.util.StringUtil;

Скачать в pdf «JSP Tag Libraries»