This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi, I'm using jsp tags and the I need to over come is that the constructor of the tag is only called once and the tag object is then reused over and over again. My tag has an attribute that is optional, so if the attribute was set during its use for 1 iteration but not required for the next one the object is used, the data remains in the tag. Does anyone know how to get around this? Jag
What container are you using? Tomcat? Resin? The behavior of the various containers around reuse of tag classes is quite different. Resin, for example, very aggressively re-uses tag instances, but is very careful to make sure that the problem you describe does not occur. Other containers may be less fastidious. Are you really experiencing this issue, or are you just surmising that it might occur? hth, bear
This is a messy issue which I had to deal with, with some help from the people on the Tomcat mailing list. If you do things correctly, they will work with all engines. First: tags can be re-used, and you can't always predict when they will be re-used. Your release() method will be called when the tag instance is completed, and should reinitialize your tag attributes. Don't use the doEndTag() method for this purpose; that's the mistake which I was making. If you use standard setter methods to set your attributes and release() to clear them, you should be fine.
Don't use the doEndTag() method for this purpose; that's the mistake which I was making.
Yeah, I learned that too the hard way about nine months ago. Ouch! In any case, be sure that you aren't doing any clever caching of values or anything along those lines, and that your tag doesn't rely on instance variables that are orthogonal to tag attributes. And never, ever call release() yourself. If you treat the setters as straight-forward bean setters as Gary stated, the container should take care of creating instances and calling the setters in the correct sequence. I've heard that weblogic has a really bad custom tag engine in this respect, but that's only heresay so take it with a grain of salt. hth, bear [ March 28, 2003: Message edited by: Bear Bibeault ]
I agree with Bear, you shouldn't actually need to reset your tag attributes because the container will do this for you, based around the rules of tag handler reuse. However, you should remember to reset instance variables that your tag uses, but aren't set through the attributes of your tag. For example, if you tag uses an iterator, then make sure that you set/reset this before use. I would recommend doing this in the doStartTag() method since this is guaranteed to be called every time. JSP 2.0 fixes all of this by introducing simple tags that are created and only ever used once. Hurray, no tag reuse issues! Simon