Using a TagExtraInfo Class for Validation
The
TagLibraryValidator
is the most powerful validation mechanism, but it comes at the price
of complexity. You need to be pretty well versed in XML to validate
the use of your tag library. I recommend that you give it a shot and
make it your first choice, but it may be overkill for a small library
with modest validation needs. If that’s the case,
you can develop TagExtraInfo
subclasses for the
individual custom actions that need validation. A
TagExtraInfo
subclass can validate the use of the
action element attributes. Optional attributes may be mutually
exclusive—if one is used, the other must not be used—or
using one optional attribute may require another optional attribute
be used as well. A TagExtraInfo
subclass can
verify rules like this, but it can’t verify that a
custom action is used correctly in the JSP page relative to other
actions.
After the JSP container has checked everything it can on its own and
has used the TagLibraryValidator
classes for all
libraries used in the page, it looks for
TagExtraInfo
declarations for each custom action
element used in the page:
<tag> <name>myOptionalAttributesAction</name> <tag-class>com.foo.MyOptionalAttributesTag</tag-class> <tei-class>com.foo.MyOptionalAttributesTEI</tei-class> ... </tag>
If it finds a <tei-class>
element for an
action, the container creates a TagData
instance
with the attribute values specified in the action element and calls
the TagExtraInfo validate( )
method:
public ValidationMessage[] ...
Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.