2004-08-12

Serialization and JSP taglibs

Why would one want to have tag libraries serialized?

This is what the spec says for TagSupport:


public class TagSupport
extends java.lang.Object
implements IterationTag, java.io.Serializable


A base class for defining new tag handlers implementing Tag.


The TagSupport class is a utility class intended to be used as the base class for new tag handlers. The TagSupport class implements the Tag and IterationTag interfaces and adds additional convenience methods including getter methods for the properties in Tag. TagSupport has one static method that is included to facilitate coordination among cooperating tags.



I am not sure if taglibs are serialized, well at least normal course of execution. Perhaps taglibs may be serialized for memory-related operations, if the demands on memory made by the container result in swapping of in-memory taglib classes to disk? If that's the case, why aren't there any notification/activation methods for taglibs?

[08/10/2004]
I'm still not sure why the tags are serialized, but the following provides more info on the JSP tag-life cycle:



ATag t = new ATag();

-- need to set required information
t.setPageContext(...);
t.setParent(...);
t.setAttribute1(value1);
t.setAttribute2(value2);

-- all ready to go
t.doStartTag();
t.doEndTag();

... other tags and template text

-- say one attribute is changed, but parent and pageContext have not changed
t.setAttribute2(value3);
t.doStartTag()
t.doEndTag()

... other tags and template text

-- assume that this new action happens to use the same attribute values
-- it is legal to reuse the same handler instance, with no changes...
t.doStartTag();
t.doEndTag();

-- OK, all done
t.release()



So the release() is guaranteed to be called on each tag, however, there maybe multiple calls to doStartTag() and doEndTag()

No comments:

Post a Comment