You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nitish Kumar <ni...@tavant.com> on 2005/07/23 12:18:21 UTC

Custom Tag release() method not being called

Hey all,
	I am trying to write a custom tag, I have a requirement to display
different form element (i.e. text box, label or textarea depending on the
flags set by user), This tag is nested inside <nested:iterate > 
	In this tag, I am also maintaining a counter which gets incremented
each time the tag is called and I am resetting the counter in the release()
method, however the release method is not being called and if I hit refresh
on the page, the counter takes the last value of previous iteration.
	
I expected that when the parent tag's doEndTag is called, it should call
release on all the child tags, is it not so? 

In any case, is there a workaround to achieve this?
	 

Thanks and Regards, 
Nitish Kumar 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Custom Tag release() method not being called

Posted by Laurie Harper <la...@holoweb.net>.
Nitish Kumar wrote:
> Hey all,
> 	I am trying to write a custom tag, I have a requirement to display
> different form element (i.e. text box, label or textarea depending on the
> flags set by user), This tag is nested inside <nested:iterate > 
> 	In this tag, I am also maintaining a counter which gets incremented
> each time the tag is called and I am resetting the counter in the release()
> method, however the release method is not being called and if I hit refresh
> on the page, the counter takes the last value of previous iteration.
> 	
> I expected that when the parent tag's doEndTag is called, it should call
> release on all the child tags, is it not so? 

Nope. See the Lifecycle of the Javadoc for custom tag handlers [1]. 
Specifically, reset() is not guaranteed to be called between tag invocations.

> In any case, is there a workaround to achieve this?

You should ensure that all tag attributes are cleared (or reset to default 
values) after doStartTag() or doEndTag() complete (note, again from the 
documentation, that doEndTag() isn't guaranteed to be called either).

You can either do this by calling release() manually or, better, provide a 
separate method for clearing tag attributes and keep release() for its 
intended purpose. Or, assuming you're using JSP 2.0, look at implementing 
SimpleTag instead of Tag.

L.

[1] 
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jspapi/javax/servlet/jsp/tagext/Tag.html

-- 
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/laurie


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org