You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Luca Passani <pa...@eunet.no> on 2005/07/23 13:30:48 UTC

TagSupport vs BodyTagSupport

Hello, I would love to hear about some taglib theory here.

My understanding is that, when creating a new tag, I can inherit from 
either TagSupport or BodyTagSupport
depending on whether I need to manipulate  the tag content or not.
For this reason, most of my tags (WALL library) inherit from TagSupport  
with the exception of one (which inherits from BodyTag).
Looking at the code for the Struts html tag-lib, I see that most tag 
inherit from BaseHandlerTag (which looks
totally reasonable to me), which, in turn, inherits from BodyTagSupport, 
even for tags that have no particular reason to do so,.

in fact, in moost cases, doAfterBody() ends up doing domething as simple as,

 if (bodyContent != null) {
            String value = bodyContent.getString().trim();
            if (value.length() > 0) {
                text = value;
            }
        }

i..e,  just comsmetic for the returned source markup.

My question is, in general, what is the rationale for inheriting from 
BodyTagSupport everywhere?
what is the performance hit when inheriting from BodyTagSupport as 
compared to TagSupport?

Thank you

Luca




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


Re: TagSupport vs BodyTagSupport

Posted by Luca Passani <pa...@eunet.no>.
Martin, Rahul

thanks a lot to you both for answers in both threads. Very instructive. 
Unfortunately I have to support both versions of JSPs, so SimpleTag is 
out of question. I found a neat trick (used in another tag-lib) which 
prevented me to support two versions of my code while supporting EL in 
both cases at the cost of having two TLDs. I was lucky there.

Unfortunately, there does not seem to be a lot of "hand-on" experience 
with tag-libs documented around, which would be really valuable when one 
is creating a new tag-lib as in my case. BTW if I am wrong, I would love 
to stand corrected

Luca

Rahul Akolkar wrote:

>
>Yes, ofcourse. 
>
>Luca - I probably should've clarified, but my comments weren't about
>the example you used, rather the question whether tags in your taglib
>should extend BodyTagSupport as a rule.
>  
>


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


Re: TagSupport vs BodyTagSupport

Posted by Rahul Akolkar <ra...@gmail.com>.
On 7/23/05, Martin Cooper <mf...@gmail.com> wrote:
<snip/>
> Rahul mentioned SimpleTagSupport, and that would have been nice, but
> that came along long after the Struts tags, and indeed the Struts tags
> still need to support earlier versions of JSP.

Yes, ofcourse. 

Luca - I probably should've clarified, but my comments weren't about
the example you used, rather the question whether tags in your taglib
should extend BodyTagSupport as a rule.

-Rahul

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


Re: TagSupport vs BodyTagSupport

Posted by Martin Cooper <mf...@gmail.com>.
On 7/23/05, Luca Passani <pa...@eunet.no> wrote:
> 
> ooops, I felt this was a general taglib question, more than a Struts
> question. It only takes struts as an example,
> but the question is "is there a reason why it makes sense to always
> subclass BodyTagSupport in a tag-library?"

Sorry, I read it as "why are almost all of the Struts tags based on
BodyTagSupport?", which would be a question for the Struts list. But I
guess I'll go ahead and answer that anyway, since it's probably the
simplest way to answer what you're asking.

The reason is exactly what you noted - that almost all of the tags
extend BaseHandlerTag, which has quite a lot of stuff in it. We needed
a common base class so that we could share all of that code, and not
have to reimplement the common attributes for each tag, and since some
of the tags process their bodies, there's no alternative but for that
base class to extend BodyTagSupport. We could have used two base
classes, but that would have meant duplicating code, and would no
doubt have led to the tags getting out of sync.

Rahul mentioned SimpleTagSupport, and that would have been nice, but
that came along long after the Struts tags, and indeed the Struts tags
still need to support earlier versions of JSP.

Hope that helps.

--
Martin Cooper


> Luca
> 
> Martin Cooper wrote:
> 
> >Once again, please ask questions about Struts on the Struts mailing
> >lists, rather than here.
> >
> >--
> >Martin Cooper
> >
> >
> >On 7/23/05, Luca Passani <pa...@eunet.no> wrote:
> >
> >
> >>Hello, I would love to hear about some taglib theory here.
> >>
> >>My understanding is that, when creating a new tag, I can inherit from
> >>either TagSupport or BodyTagSupport
> >>depending on whether I need to manipulate  the tag content or not.
> >>For this reason, most of my tags (WALL library) inherit from TagSupport
> >>with the exception of one (which inherits from BodyTag).
> >>Looking at the code for the Struts html tag-lib, I see that most tag
> >>inherit from BaseHandlerTag (which looks
> >>totally reasonable to me), which, in turn, inherits from BodyTagSupport,
> >>even for tags that have no particular reason to do so,.
> >>
> >>in fact, in moost cases, doAfterBody() ends up doing domething as simple as,
> >>
> >> if (bodyContent != null) {
> >>            String value = bodyContent.getString().trim();
> >>            if (value.length() > 0) {
> >>                text = value;
> >>            }
> >>        }
> >>
> >>i..e,  just comsmetic for the returned source markup.
> >>
> >>My question is, in general, what is the rationale for inheriting from
> >>BodyTagSupport everywhere?
> >>what is the performance hit when inheriting from BodyTagSupport as
> >>compared to TagSupport?
> >>
> >>Thank you
> >>
> >>Luca
> >>
> >>
> >>
> >>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
>

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


Re: TagSupport vs BodyTagSupport

Posted by Rahul P Akolkar <ak...@us.ibm.com>.
Luca Passani <pa...@eunet.no> wrote on 07/23/2005 02:28:14 PM:
>
> ooops, I felt this was a general taglib question, more than a Struts 
> question. It only takes struts as an example,
> but the question is "is there a reason why it makes sense to always 
> subclass BodyTagSupport in a tag-library?"
<snip/>

Outside of frameworks, I am usually guarded about any statement that 
matches "always do *", especially those related to patterns and 
subclassing.

I often extend SimpleTagSupport (JSP 2.0), and have on occassions, 
preferred it over BodyTagSupport, due to its simpler life cycle.

For a far more detailed commentary, please read the jsp.tagext Javadocs 
here [ 
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/package-summary.html 
]

-Rahul

Re: TagSupport vs BodyTagSupport

Posted by Luca Passani <pa...@eunet.no>.
ooops, I felt this was a general taglib question, more than a Struts 
question. It only takes struts as an example,
but the question is "is there a reason why it makes sense to always 
subclass BodyTagSupport in a tag-library?"

Luca

Martin Cooper wrote:

>Once again, please ask questions about Struts on the Struts mailing
>lists, rather than here.
>
>--
>Martin Cooper
>
>
>On 7/23/05, Luca Passani <pa...@eunet.no> wrote:
>  
>
>>Hello, I would love to hear about some taglib theory here.
>>
>>My understanding is that, when creating a new tag, I can inherit from
>>either TagSupport or BodyTagSupport
>>depending on whether I need to manipulate  the tag content or not.
>>For this reason, most of my tags (WALL library) inherit from TagSupport
>>with the exception of one (which inherits from BodyTag).
>>Looking at the code for the Struts html tag-lib, I see that most tag
>>inherit from BaseHandlerTag (which looks
>>totally reasonable to me), which, in turn, inherits from BodyTagSupport,
>>even for tags that have no particular reason to do so,.
>>
>>in fact, in moost cases, doAfterBody() ends up doing domething as simple as,
>>
>> if (bodyContent != null) {
>>            String value = bodyContent.getString().trim();
>>            if (value.length() > 0) {
>>                text = value;
>>            }
>>        }
>>
>>i..e,  just comsmetic for the returned source markup.
>>
>>My question is, in general, what is the rationale for inheriting from
>>BodyTagSupport everywhere?
>>what is the performance hit when inheriting from BodyTagSupport as
>>compared to TagSupport?
>>
>>Thank you
>>
>>Luca
>>
>>
>>    
>>


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


Re: TagSupport vs BodyTagSupport

Posted by Martin Cooper <mf...@gmail.com>.
Once again, please ask questions about Struts on the Struts mailing
lists, rather than here.

--
Martin Cooper


On 7/23/05, Luca Passani <pa...@eunet.no> wrote:
> 
> Hello, I would love to hear about some taglib theory here.
> 
> My understanding is that, when creating a new tag, I can inherit from
> either TagSupport or BodyTagSupport
> depending on whether I need to manipulate  the tag content or not.
> For this reason, most of my tags (WALL library) inherit from TagSupport
> with the exception of one (which inherits from BodyTag).
> Looking at the code for the Struts html tag-lib, I see that most tag
> inherit from BaseHandlerTag (which looks
> totally reasonable to me), which, in turn, inherits from BodyTagSupport,
> even for tags that have no particular reason to do so,.
> 
> in fact, in moost cases, doAfterBody() ends up doing domething as simple as,
> 
>  if (bodyContent != null) {
>             String value = bodyContent.getString().trim();
>             if (value.length() > 0) {
>                 text = value;
>             }
>         }
> 
> i..e,  just comsmetic for the returned source markup.
> 
> My question is, in general, what is the rationale for inheriting from
> BodyTagSupport everywhere?
> what is the performance hit when inheriting from BodyTagSupport as
> compared to TagSupport?
> 
> Thank you
> 
> Luca
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
>

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