Originally posted by Sita Kotamraju:
i dont know how to do validation yet.
To do validation, you can override the isValid() method in your subclass of TagExtraInfo (TEI). isValid() accepts a TagData object as its single parameter. For instance, to blindly deny all use of the tag (just as an exercise), you could include the following in your TEI subclass:
public boolean isValid(TagData us) {
return false;
}
TagData has methods like getAttribute(
String) that lets you check the (non-rtexprvalue) attributes of the tag's invocation. I often use a utility method, isSpecified(), to determine whether an attribute was specified or not. (For some reason, this is often what I need to validate against -- was attribute X specified without attribute Y also being specified, and so forth.) isSpecified() looks like this:
public static boolean isSpecified(TagData data, String attributeName) {
return (data.getAttribute(attributeName) != null);
}
In general, TEIs are somewhat limited. I recommend
JSP 1.2-style TagLibraryValidator (TLV_ classes. While these are somewhat more difficult and tedious to write, they're also much more powerful. (Has anyone here written TLVs? I sometimes feel like I'm the only one.) I included a few instructive examples of TLVs in the JSTL reference-implementation, specifically to encourage their wider adoption. You can see the code at the Jakarta Taglibs CVS archive. There are some clean examples of TEIs there too.
Hope that helps!