You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Br...@i2.com on 2001/04/09 21:19:56 UTC

File include within the scope of a custom tag within a template

Hi,
     I have a custom tag, and would like to have a template include file
within the body of the custom tag:
<foo:myCustomTag>
    <template:get name='content'/>                 <!-- content is
template-defined attribute -->
</foo:myCustomTag>

Unfortunately, this gives the "illegal to flush within custom tag" error
message due to the include resulting from the get being in the body of a
custom tag.  However, I can use a hardcoded filename and a jsp include to
include the approriate file:
<foo:myCustomTag>
    <%@include file="content33.jsp" />
</foo:myCustomTag>

The above works.  Given that I'd really like to consolidate the use of the
custom tag by locating it within the template, I'm trying everything in
order to get a "paramerized" include to work within the template scope.
However, all attempts at parameterizing the "file" value of the direct
include have failed, including:
<% String filename = "content33.jsp";   // for now hardcode, eventually set
from pageContext.getAttribute(..., PAGE_SCOPE)
%>
<foo:myCustomTag>
    <%@include file="<%= filename%>" %>        <!-- Gives bad file arg -->
    OR <%@inlude file="<template:get name='contentName/>" %>   <!--
template contentName attr has direct='true' property -->
    OR <jsp:directive.include file="<%=filename%>" />                <!--
jsp:directive.include wouln't work even with hardcoded filename for tomcat
3.2.1 -->
   OR ....
</foo:myCustomTag>


     Any ideas on how to get a paramterized filename to be included within
the body of a custom tag?  Or to get the template/component tag libaries to
not flush in order to faciliate using the "get" within the scope of a
custom tag?  At this point, clever hacks/kludges are welcome!

thanks,
Brad

p.s. -   I have not experimented with component tld/library, as I am under
the impression that it also flushes the output, and would have the same
problem as the template package documented above.



Re: File include within the scope of a custom tag within a template

Posted by Cedric Dumoulin <ce...@lifl.fr>.
  Hi Brad,

  There is two ways to deal with the body of a custom tag : extend TagSupport
or extend BodyTagSupport.

   *  In the first case, you can do include() (and so use <get> or <insert>),
     you can output body evaluation in the current out, but you can't get the
     body in your custom tag doEndTag(). As an example, try to do <get> or
     <insert> inside an <html:form> : this work !
   * In the second case, your custom tag create a BodyContent, and evaluation
     of the body is done with BodyContent. This forbid the use of flush(),
     because the new created out doesn't support it. Unfortunately, flush() is
     called automatically by include() ;-(. Well known problem is trying to do
     a <get> or <insert> inside an <logic:iterate> tag. This doesn't work with
     currentjsp1.1 implementation . Jsp1.2 propose a new IterationTag that will
     work.

  For your problem, if you don't need to deal with the custom tag body in
doEndTag(), extend TagSupport and return EVAL_BODY_INCLUDE, this must work.
  Otherwise, try another approach to your problem. I can't help here, as I
don't know what you want to do in your custom tag.

  Cedric

P.S. : If you have some trouble to write me directly, try this :
cedric@apache.org


Brad_Miller@i2.com wrote:

> Hi,
>      I have a custom tag, and would like to have a template include file
> within the body of the custom tag:
> <foo:myCustomTag>
>     <template:get name='content'/>                 <!-- content is
> template-defined attribute -->
> </foo:myCustomTag>
>
> Unfortunately, this gives the "illegal to flush within custom tag" error
> message due to the include resulting from the get being in the body of a
> custom tag.  However, I can use a hardcoded filename and a jsp include to
> include the approriate file:
> <foo:myCustomTag>
>     <%@include file="content33.jsp" />
> </foo:myCustomTag>
>
> The above works.  Given that I'd really like to consolidate the use of the
> custom tag by locating it within the template, I'm trying everything in
> order to get a "paramerized" include to work within the template scope.
> However, all attempts at parameterizing the "file" value of the direct
> include have failed, including:
> <% String filename = "content33.jsp";   // for now hardcode, eventually set
> from pageContext.getAttribute(..., PAGE_SCOPE)
> %>
> <foo:myCustomTag>
>     <%@include file="<%= filename%>" %>        <!-- Gives bad file arg -->
>     OR <%@inlude file="<template:get name='contentName/>" %>   <!--
> template contentName attr has direct='true' property -->
>     OR <jsp:directive.include file="<%=filename%>" />                <!--
> jsp:directive.include wouln't work even with hardcoded filename for tomcat
> 3.2.1 -->
>    OR ....
> </foo:myCustomTag>
>
>      Any ideas on how to get a paramterized filename to be included within
> the body of a custom tag?  Or to get the template/component tag libaries to
> not flush in order to faciliate using the "get" within the scope of a
> custom tag?  At this point, clever hacks/kludges are welcome!
>
> thanks,
> Brad
>
> p.s. -   I have not experimented with component tld/library, as I am under
> the impression that it also flushes the output, and would have the same
> problem as the template package documented above.