JSP Tag Libraries

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

public class TestTagExtraInfo extends TagExtraInfo {

public boolean isValid(TagData data)


String condition =

data.getAttributeString(«condition»); String[] parsed =

StringUtil.splitArray(condition, » «);



if((parsed[0].equals(TestTag.OPER_EXISTS) ||

parsed[0].equals(TestTag.OPER_NEXISTS))    &&

parsed.length == 1)    {

return true;


if(parsed.length == 2 &&

null != TestTag.operators.get(parsed[0]))    {

return true;


return false;



о Checking the unary operators for correctness, we need to individually check each operator name.
e Checking the binary operators for correctness, all we need is a single look-up in the operator table.

TestTagExtraInfo provides one more reason for using an operator table instead of hard-coding the operators in TestTag; just look at the difference between the validation of the unary and binary conditions. Since the implementation of the unary operators is hard-coded in TestTag, TestTagExtraInfo must create an if statement with the specific unary operator, which will force a developer that adds another unary operator to modify both as well as TestTag. On the other hand, since the binary operators are implemented with an operator look-up table, all that

is needed to validate the binary operator is to search the look-up table for a valid operator. Happily, this means that a developer will not need to change TestTagEx-trainfo in order to add new operators.

9.3.3 TLD for the advanced condition tags

To complete our discussion of advanced condition tags, we shall also provide the important tag library descriptor, as well as sample JSP code that take advantage of the condition tags.

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