JSP Tag Libraries

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


Supplying a TagExtraInfo implementation is not mandatory (unless you export variables); but neglecting its implementation is not good, not good at all.


If your tags have a complex set of attributes, with limits on the attribute values and the relations between them (as we saw in the reflection case), you must provide a TagExtraInfo implementation along with your tags. Even for tags with only attribute values constraints, you will want to implement TagExtraInfo.


The reason is, even if you have great tag documentation, errors will be associated with the tag attribute usage, due to copy-paste operations performed by the tag’s user or, perhaps, innocent confusion. If TagExtraInfo implementation is not provided, two problems will arise:


1    The JSP file will compile, but will throw runtime exceptions that the creator of the JSP file does not follow. If I am the developer of the JSP file and I get a NullPointerException from a tag (a missing attribute, actually), I will immediately consider it a bug in the tag handler. The tag developer will consider it a usage error.


2    Once the JSP file compiles and serves a request, the developer of the JSP file assumes that tag usage in this file is correct, because the JSP file managed to compile and serve a request. Yet, as we know, tags may stand inside fragments of conditional JSP that your tests did not cover. Thus, you have usage errors in JSP files that compile and run, and which you assume to be okay.


The only way to avoid these problems is to provide TagExtrainfo to validate the attribute syntax. This solves the first problem since the JSP translator will generate error messages while translating the file, and the messages will say, in effect, “There is an error in the attributes values for tag foo”, which leaves no ambiguity in the nature of the error. The second problem is resolved since the JSP translator covers the entire JSP file without paying attention to conditional HTML (so the entire JSP file is checked for errors).

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