confused about custom tags keeping state

L

luca

Hello, I am designing a tag library. My problem is that
my tags (tomcat 4.1.18 on win2k) seem to retain the status
from one invocation to the next (i.e. variables are
not initialized each time).

I tried to look for solutions on google, but I only gather
that I should do something about calling the release() method
somewhere (but where?)
Also, I am confused about multi-threading (what if a doInitTag
kicks in while a previous instance of the tag is being processed?)

I have found a workaround by manually reinitializing the tags
at the beginning of doInitTag(), but this seems unelegant to me...

ideas? real knowledge?

thank you

luca
 
M

Manavendra Gupta

Hi luca

The documentation for the Interface Tag states "There are two main actions:
doStartTag and doEndTag. Once all appropriate properties have been
initialized, the doStartTag and doEndTag methods can be invoked on the tag
handler. Between these invocations, the tag handler is assumed to hold a
state that must be preserved. After the doEndTag invocation, the tag handler
is available for further invocations (and it is expected to have retained
its properties)."

The release() method is invoked once all invocations on the tag handler are
completed. Once a release method is invoked all properties, including parent
and pageContext, are assumed to have been reset to an unspecified value. The
page compiler guarantees that release() will be invoked on the Tag handler
before the handler is released to the GC.

So that explains the value being retained.

I normally define my own destructor or initialiser method which I invoke in
the doEndTag(), re-initializing the members.

Since each tag would reside in a different pageContext the state will be
preserved for a thread processing the page.

Cheers
Manav
 
L

luca

Thanks a lot for your answer. thinking about this again, what about
explicitly re-initializing the state at the beginning of doStartTag() ?

Will this guarantee that the old state is reset?

do you see any problem with that approach?

thank you

luca
 
M

Manavendra Gupta

Yes, that should work too

Cheers
Manav
luca said:
Thanks a lot for your answer. thinking about this again, what about
explicitly re-initializing the state at the beginning of doStartTag() ?

Will this guarantee that the old state is reset?

do you see any problem with that approach?

thank you

luca
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top