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 Lukas Bradley <lu...@somnia.com> on 2003/10/27 01:34:04 UTC

Tags creating Tags

Hi all,

Maybe I'm just tired, but the answer to this is not to be found.  I could me
making this harder than it is, or something might be right in front of me,
and I don't see it.

What I want is a custom tag that creates other custom tags.  Here is a
simple example:

<lukas:myTag lang="en" />

Should produce something like this:

<table>
  <tr><td>English</td></tr>
  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
   <!-- Imagine a lot more custom tags here -->
</table>

Which should then evaluate to:

<table>
  <tr><td>English</td></tr>
  <tr><td><input type="file" name="formFile" value=""
class="FormField"></td></tr>
   <!-- Imagine a lot more custom tags rendering here. -->
</table>

I've thought about trying to extend BodyTagSupport, return
EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
constructor, and no way to set its content.

I want to maintain the functionality gained from Struts-like custom tags,
while extracting the creation of them in a super-duper momma tag.  Any help?

Lukas




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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
> One way of accomplishing what you want to do, I think, is simply making
> calls to the appropriate Struts classes that are called when <html:link>
> is parsed & compiled. Instead of outputting an <html:link> - just call
> those methods with the arguments that you would write out as <html:link>
> attributes, and you should get pretty close to what you're trying to
> achieve (without the performance hit ;)

That's EXACTLY what I want to do.  However, I don't want to have to write
all the calls to doStartTag(), then determine what action should be taken
from the return int, etc etc etc.

I was hoping that grunt work was already done for me, or existed within the
Jasper packages.

Lukas




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


Re: Tags creating Tags

Posted by "Ruth, Brice" <br...@fiskars.com>.
One way of accomplishing what you want to do, I think, is simply making 
calls to the appropriate Struts classes that are called when <html:link> 
is parsed & compiled. Instead of outputting an <html:link> - just call 
those methods with the arguments that you would write out as <html:link> 
attributes, and you should get pretty close to what you're trying to 
achieve (without the performance hit ;)

Brice

Craig R. McClanahan wrote:

> Lukas Bradley wrote:
>
>> Hi all,
>>
>> Maybe I'm just tired, but the answer to this is not to be found.  I 
>> could me
>> making this harder than it is, or something might be right in front 
>> of me,
>> and I don't see it.
>>
>> What I want is a custom tag that creates other custom tags.  Here is a
>> simple example:
>>
>> <lukas:myTag lang="en" />
>>
>> Should produce something like this:
>>
>> <table>
>>  <tr><td>English</td></tr>
>>  <tr><td><html:file property="formFile" 
>> styleClass="FormField"/></td></tr>
>>   <!-- Imagine a lot more custom tags here -->
>> </table>
>>
>> Which should then evaluate to:
>>
>> <table>
>>  <tr><td>English</td></tr>
>>  <tr><td><input type="file" name="formFile" value=""
>> class="FormField"></td></tr>
>>   <!-- Imagine a lot more custom tags rendering here. -->
>> </table>
>>
>> I've thought about trying to extend BodyTagSupport, return
>> EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in 
>> doAfterBody(),
>> then return EVAL_PAGE() in doEndTag().  However, BodyContent has a 
>> protected
>> constructor, and no way to set its content.
>>
>> I want to maintain the functionality gained from Struts-like custom 
>> tags,
>> while extracting the creation of them in a super-duper momma tag.  
>> Any help?
>>
>>  
>>
>
> It's not much help, except in the sense that it will put your search 
> for the answer out of it's misery :-).  What you are trying to do is 
> not supported by JSP -- the reason is that custom tags are converted 
> into appropriate method calls at page compile time.  After that, they 
> are just executed.  To accomplish what you are after, you would need 
> another layer of compilation.
>
> You'll need to come up with a different approach to accomplish what 
> you are after.
>
>> Lukas
>>
>>  
>>
> Craig
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>

-- 
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.



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


Re: Tags creating Tags

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Lukas Bradley wrote:

>Hi all,
>
>Maybe I'm just tired, but the answer to this is not to be found.  I could me
>making this harder than it is, or something might be right in front of me,
>and I don't see it.
>
>What I want is a custom tag that creates other custom tags.  Here is a
>simple example:
>
><lukas:myTag lang="en" />
>
>Should produce something like this:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
>   <!-- Imagine a lot more custom tags here -->
></table>
>
>Which should then evaluate to:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><input type="file" name="formFile" value=""
>class="FormField"></td></tr>
>   <!-- Imagine a lot more custom tags rendering here. -->
></table>
>
>I've thought about trying to extend BodyTagSupport, return
>EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
>then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
>constructor, and no way to set its content.
>
>I want to maintain the functionality gained from Struts-like custom tags,
>while extracting the creation of them in a super-duper momma tag.  Any help?
>
>  
>

It's not much help, except in the sense that it will put your search for 
the answer out of it's misery :-).  What you are trying to do is not 
supported by JSP -- the reason is that custom tags are converted into 
appropriate method calls at page compile time.  After that, they are 
just executed.  To accomplish what you are after, you would need another 
layer of compilation.

You'll need to come up with a different approach to accomplish what you 
are after.

>Lukas
>
>  
>
Craig



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


Re: Tags creating Tags

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Lukas Bradley wrote:

>Hi all,
>
>Maybe I'm just tired, but the answer to this is not to be found.  I could me
>making this harder than it is, or something might be right in front of me,
>and I don't see it.
>
>What I want is a custom tag that creates other custom tags.  Here is a
>simple example:
>
><lukas:myTag lang="en" />
>
>Should produce something like this:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
>   <!-- Imagine a lot more custom tags here -->
></table>
>
>Which should then evaluate to:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><input type="file" name="formFile" value=""
>class="FormField"></td></tr>
>   <!-- Imagine a lot more custom tags rendering here. -->
></table>
>
>I've thought about trying to extend BodyTagSupport, return
>EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
>then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
>constructor, and no way to set its content.
>
>I want to maintain the functionality gained from Struts-like custom tags,
>while extracting the creation of them in a super-duper momma tag.  Any help?
>
>  
>

It's not much help, except in the sense that it will put your search for 
the answer out of it's misery :-).  What you are trying to do is not 
supported by JSP -- the reason is that custom tags are converted into 
appropriate method calls at page compile time.  After that, they are 
just executed.  To accomplish what you are after, you would need another 
layer of compilation.

You'll need to come up with a different approach to accomplish what you 
are after.

>Lukas
>
>  
>
Craig



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


Re: Tags creating Tags

Posted by "Ruth, Brice" <br...@fiskars.com>.
I don't think this is possible, as it would require that the JSP be 
recursively parsed, right? When a tag writes to the output stream, 
that's going straight to the browser, really - it would need to be 
reevaluated by the JSP engine, in order to support what you are trying 
to do, and in theory, it would need to be indefinitely reevaluated, 
until no more JSP tags exist to be evaluated.

In short, I don't think there's an answer to this ... I know Apache2 can 
now chain filters (so the output from something like mod_jk could be 
re-evaluated by PHP or something), but I've never seen anything where 
the same filter/parser/whatever reevaluates its own output. In theory, 
this would be possible via various scripting hacks, but since Java (and 
JSP) is compiled, I'd say it would be awfully difficult to achieve - and 
awfully poor in performance - since the output of YOUR tag would need to 
be recompiled each time a request came in, since there would be no way 
to predict (and cache) the output of your tag, right?

Very poor performance, indeed! :)

Brice

Lukas Bradley wrote:

>Hi all,
>
>Maybe I'm just tired, but the answer to this is not to be found.  I could me
>making this harder than it is, or something might be right in front of me,
>and I don't see it.
>
>What I want is a custom tag that creates other custom tags.  Here is a
>simple example:
>
><lukas:myTag lang="en" />
>
>Should produce something like this:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
>   <!-- Imagine a lot more custom tags here -->
></table>
>
>Which should then evaluate to:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><input type="file" name="formFile" value=""
>class="FormField"></td></tr>
>   <!-- Imagine a lot more custom tags rendering here. -->
></table>
>
>I've thought about trying to extend BodyTagSupport, return
>EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
>then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
>constructor, and no way to set its content.
>
>I want to maintain the functionality gained from Struts-like custom tags,
>while extracting the creation of them in a super-duper momma tag.  Any help?
>
>Lukas
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>  
>

-- 
Brice D. Ruth
Sr. IT Analyst
Fiskars Brands, Inc.



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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
I apologize for the original cross-post.  I was hoping there might be a
Struts method to do what I wanted.

Here is something I wrote to the other group, after a post from Felipe Leme.

> I think you can accomplish what you're looking for using JSP 2.0 and tag
> files.

Yep.  That's exactly what I'm looking for.  Now Tomcat 5 just needs to be
released, because I'm stuck with JSP 1.2 for now.  *sniff*

Thanks for the help everyone.  I'm including a snippet from the JSP 2.0 PFD
3.

Lukas

JSP.8.1 Overview

As of JSP version 2.0, the JSP Compiler is required to recognize tag files.
A tag file is a source file that provides a way for a page author to
abstract a segment of JSP code and make it reusable via a custom action.

Tag files allow a JSP page author to create tag libraries using JSP syntax.
This means that page authors no longer need to know Java or ask someone who
knows Java to write a tag extension. Even for page authors or tag library
developers who know Java, writing tag files is more convenient when
developing tags that primarily output template text.







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


Re: Tags creating Tags

Posted by Mark Mahieu <ma...@twistedbanana.demon.co.uk>.
Hi Lukas,

If I understand you correctly you need to look into the pushBody and 
popBody methods on PageContext.  Basically, in doStartTag(), call 
pageContext.pushBody() then in doEndTag() you call 
pageContext.popBody(), retrieve the BodyContent's value, muck about with 
it to your heart's content, then output your transformed markup to the 
current JspWriter.

Something like that anyway.  This is off the top of my head so I may be 
remembering the semantics slightly wrong, but I've definitely done this 
before....


class MyTag extends BodyTagSupport {

    public int doStartTag() {

        pageContext.pushBody();

        return EVAL_BODY_INCLUDE;
    }

    public int doEndTag() {

        pageContext.popBody();
        String transformedMarkup =
    doSomeTransformations(getBodyContent().getString());
        pageContext.getOut().print(transformedMarkup);

        return EVAL_PAGE;
    }

}

Hope that helps,

Mark



Lukas Bradley wrote:

>Hi all,
>
>Maybe I'm just tired, but the answer to this is not to be found.  I could me
>making this harder than it is, or something might be right in front of me,
>and I don't see it.
>
>What I want is a custom tag that creates other custom tags.  Here is a
>simple example:
>
><lukas:myTag lang="en" />
>
>Should produce something like this:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
>   <!-- Imagine a lot more custom tags here -->
></table>
>
>Which should then evaluate to:
>
><table>
>  <tr><td>English</td></tr>
>  <tr><td><input type="file" name="formFile" value=""
>class="FormField"></td></tr>
>   <!-- Imagine a lot more custom tags rendering here. -->
></table>
>
>I've thought about trying to extend BodyTagSupport, return
>EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
>then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
>constructor, and no way to set its content.
>
>I want to maintain the functionality gained from Struts-like custom tags,
>while extracting the creation of them in a super-duper momma tag.  Any help?
>
>Lukas
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>  
>



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


Re: Tags creating Tags

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Lukas Bradley wrote:

>Ruth, Craig, and lurkers,
>
>I think what I'm after boils down to a method like this:
>
>public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
>JspException
>
>  
>
A look at the JSP Specification will tell you that this would not work 
at all for a classic tag handler (i.e. implements Tag or implements 
BodyTag).

>After creating the tag manually, you could pass it to this method, and have
>it rendered.  The return value of a String should be the final output of the
>Tag.  The method would check for BodyTag, IterationTag, etc support, and
>react to it.  This way, the user could embed custom tags (Struts or
>otherwise) within their own custom tags.
>
>I'm surprised a method like this doesn't already exist.  This wouldn't be
>recursive, nor would it recompile on each shot.  You may be right in calling
>this a tad "hackish," but it would be useful, no?  I can even think of
>another method that would be the incredi-hack:
>
>public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
>JspException
>
>Where you pass in "<html:file .... />" instead of the Tag object itself.
>Now that would be aggressive.
>
>For another approach, the JspFragment interface looks promising.  However,
>I'm stuck with Tomcat 4.1 for now, so JSP 2.0 is out.
>
>  
>

I think the approach you suggest is problematic, for many of the reasons 
that Action chaining is problematic.  The most serious issue is that 
you're trying to use a JSP artifact (a custom tag implementation class) 
for something it was never designed to do (be a reusable "output 
generator" outside the context of the very strict and complex lifecycle 
for tag instances described in the JSP specfiication).  "Hackish" does 
not begin to describe how much trouble this kind of anti-object-oriented 
approach will lead you to in the long run.

The right answer would be to create your own tag class that does exactly 
what you want.  If your tag wants to leverage functionality from 
existing tag classes (and you don't want to cut-n-paste), either make 
your class a subclass of the existing one (presuming the stuff you need 
is already abstracted into useful protected methods), or abstract the 
stuff you need into utility classes that can be shared between your tag 
and the standard ones, and then lobby to have the same factoring done in 
the standard classes.

This is the foundational basis on which all Struts tag classes are 
organized, and has proven to support a pretty rich library of tag class 
implementations that (in many cases) reuse or specialize protected 
methods in their subclasses.  In no case was a "generate a tag" type of 
hack considered, because it's not necessary.  All that's necessary is 
applying sound design practices for factoring reusable code into 
reusable chunks.  I won't try to claim that we've done a perfect job at 
the current factoring, but the existence of something like struts-el 
(which was basically built on top of the existing tags, without having 
to rip them apart) is pretty good evidence that we're on the right track.

Trying to interfere with the tag instance lifecycle that the JSP page 
compiler assumes pretty much guarantees you'll end up with disaster.

>Lukas
>
>  
>

Craig



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


Re: Tags creating Tags

Posted by Felipe Leme <ja...@felipeal.net>.
On Monday 27 October 2003 12:46 am, Lukas Bradley wrote:

> Yep.  That's exactly what I'm looking for.  Now Tomcat 5 just needs to be
> released, because I'm stuck with JSP 1.2 for now.  *sniff*

You're lucky - some of the projects I work on are stuck on JSP 1.1 or even JSP 
1.0/JServ :-(



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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
> I think you can accomplish what you're looking for using JSP 2.0 and tag
> files.

Yep.  That's exactly what I'm looking for.  Now Tomcat 5 just needs to be
released, because I'm stuck with JSP 1.2 for now.  *sniff*

Thanks for the help everyone.  I'm including a snippet from the JSP 2.0 PFD
3.

Lukas

JSP.8.1 Overview

As of JSP version 2.0, the JSP Compiler is required to recognize tag files.
A

tag file is a source file that provides a way for a page author to abstract
a segment

of JSP code and make it reusable via a custom action.

Tag files allow a JSP page author to create tag libraries using JSP syntax.
This

means that page authors no longer need to know Java or ask someone who knows

Java to write a tag extension. Even for page authors or tag library
developers who

know Java, writing tag files is more convenient when developing tags that

primarily output template text.




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


Re: Tags creating Tags

Posted by Felipe Leme <ja...@felipeal.net>.
Lukas,

I think you can accomplish what you're looking for using JSP 2.0 and tag 
files.

If I'm correct (I haven't used them yet, only read about), you can create tag 
files that uses other custom tags.

Felipe


On Monday 27 October 2003 12:07 am, Lukas Bradley wrote:

> I'm surprised a method like this doesn't already exist.  This wouldn't be


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


Re: Tags creating Tags

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Lukas Bradley wrote:

>Ruth, Craig, and lurkers,
>
>I think what I'm after boils down to a method like this:
>
>public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
>JspException
>
>  
>
A look at the JSP Specification will tell you that this would not work 
at all for a classic tag handler (i.e. implements Tag or implements 
BodyTag).

>After creating the tag manually, you could pass it to this method, and have
>it rendered.  The return value of a String should be the final output of the
>Tag.  The method would check for BodyTag, IterationTag, etc support, and
>react to it.  This way, the user could embed custom tags (Struts or
>otherwise) within their own custom tags.
>
>I'm surprised a method like this doesn't already exist.  This wouldn't be
>recursive, nor would it recompile on each shot.  You may be right in calling
>this a tad "hackish," but it would be useful, no?  I can even think of
>another method that would be the incredi-hack:
>
>public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
>JspException
>
>Where you pass in "<html:file .... />" instead of the Tag object itself.
>Now that would be aggressive.
>
>For another approach, the JspFragment interface looks promising.  However,
>I'm stuck with Tomcat 4.1 for now, so JSP 2.0 is out.
>
>  
>

I think the approach you suggest is problematic, for many of the reasons 
that Action chaining is problematic.  The most serious issue is that 
you're trying to use a JSP artifact (a custom tag implementation class) 
for something it was never designed to do (be a reusable "output 
generator" outside the context of the very strict and complex lifecycle 
for tag instances described in the JSP specfiication).  "Hackish" does 
not begin to describe how much trouble this kind of anti-object-oriented 
approach will lead you to in the long run.

The right answer would be to create your own tag class that does exactly 
what you want.  If your tag wants to leverage functionality from 
existing tag classes (and you don't want to cut-n-paste), either make 
your class a subclass of the existing one (presuming the stuff you need 
is already abstracted into useful protected methods), or abstract the 
stuff you need into utility classes that can be shared between your tag 
and the standard ones, and then lobby to have the same factoring done in 
the standard classes.

This is the foundational basis on which all Struts tag classes are 
organized, and has proven to support a pretty rich library of tag class 
implementations that (in many cases) reuse or specialize protected 
methods in their subclasses.  In no case was a "generate a tag" type of 
hack considered, because it's not necessary.  All that's necessary is 
applying sound design practices for factoring reusable code into 
reusable chunks.  I won't try to claim that we've done a perfect job at 
the current factoring, but the existence of something like struts-el 
(which was basically built on top of the existing tags, without having 
to rip them apart) is pretty good evidence that we're on the right track.

Trying to interfere with the tag instance lifecycle that the JSP page 
compiler assumes pretty much guarantees you'll end up with disaster.

>Lukas
>
>  
>

Craig



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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
Ruth, Craig, and lurkers,

I think what I'm after boils down to a method like this:

public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
JspException

After creating the tag manually, you could pass it to this method, and have
it rendered.  The return value of a String should be the final output of the
Tag.  The method would check for BodyTag, IterationTag, etc support, and
react to it.  This way, the user could embed custom tags (Struts or
otherwise) within their own custom tags.

I'm surprised a method like this doesn't already exist.  This wouldn't be
recursive, nor would it recompile on each shot.  You may be right in calling
this a tad "hackish," but it would be useful, no?  I can even think of
another method that would be the incredi-hack:

public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
JspException

Where you pass in "<html:file .... />" instead of the Tag object itself.
Now that would be aggressive.

For another approach, the JspFragment interface looks promising.  However,
I'm stuck with Tomcat 4.1 for now, so JSP 2.0 is out.

Lukas




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


Re: Tags creating Tags

Posted by Mark Mahieu <ma...@twistedbanana.demon.co.uk>.
I said,

 > Hi Lukas,
 >
 > If I understand you correctly ...

But I didn't (understand that is).  I guess my reading comprehension 
skills at 6am just aren't up to it ;)

So just disregard my last ....

Mark


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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
Ruth, Craig, and lurkers,

I think what I'm after boils down to a method like this:

public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
JspException

After creating the tag manually, you could pass it to this method, and have
it rendered.  The return value of a String should be the final output of the
Tag.  The method would check for BodyTag, IterationTag, etc support, and
react to it.  This way, the user could embed custom tags (Struts or
otherwise) within their own custom tags.

I'm surprised a method like this doesn't already exist.  This wouldn't be
recursive, nor would it recompile on each shot.  You may be right in calling
this a tad "hackish," but it would be useful, no?  I can even think of
another method that would be the incredi-hack:

public String renderTag(PageContext pPageContext, Tag pTagToRender) throws
JspException

Where you pass in "<html:file .... />" instead of the Tag object itself.
Now that would be aggressive.

For another approach, the JspFragment interface looks promising.  However,
I'm stuck with Tomcat 4.1 for now, so JSP 2.0 is out.

Lukas




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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
Mike emailed me this idea last night, and I think it's the best yet.

Brilliant solution, Mike.

Lukas

"Mike Jasnowski" <mj...@bea.com> wrote in message
news:MLEMLKNPCAGCLECPELMICEKHEGAA.mjasnows@bea.com...
> Going from your example, I'm not sure why you even need to subclass a
Struts
> tag to get the output you described. You should be able to code something
> like this on your JSP:
>
> <lukas:myTag lang="en">
>   <html:file property="formFile" styleClass="FormField"/>
> </lukas:myTag>
>
>
> The tag handling flow would look like (similar to what you proposed
> earlier):
>
>  myTag.doStartTag();
>
>  pageContext.getOut().println("<table><tr><td>");
>
>  *include output of body of custom tag here, which might be Struts tags
> which are invoked.
>
>  myTag.doEndTag();
>
>  pageContext.getOut().println("</td></tr></table>");
>
>
>  Which would evaluate to
>
>
>  <table>
>   <tr>
>    <td>
>     <input type="file" name="formFile" value="" class="FormField">
>    </td>
>   </tr>
>  </table>
>
> All this w/o changing or subclassing a Struts tag, the only Custom tag
work
> is myTag.
>
> HTH,
> Mike
>
> -----Original Message-----
> From: Lukas Bradley [mailto:lukas@somnia.com]
> Sent: Sunday, October 26, 2003 7:34 PM
> To: struts-user@jakarta.apache.org
> Cc: taglibs-user@jakarta.apache.org
> Subject: Tags creating Tags
>
>
> Hi all,
>
> Maybe I'm just tired, but the answer to this is not to be found.  I could
me
> making this harder than it is, or something might be right in front of me,
> and I don't see it.
>
> What I want is a custom tag that creates other custom tags.  Here is a
> simple example:
>
> <lukas:myTag lang="en" />
>
> Should produce something like this:
>
> <table>
>   <tr><td>English</td></tr>
>   <tr><td><html:file property="formFile"
styleClass="FormField"/></td></tr>
>    <!-- Imagine a lot more custom tags here -->
> </table>
>
> Which should then evaluate to:
>
> <table>
>   <tr><td>English</td></tr>
>   <tr><td><input type="file" name="formFile" value=""
> class="FormField"></td></tr>
>    <!-- Imagine a lot more custom tags rendering here. -->
> </table>
>
> I've thought about trying to extend BodyTagSupport, return
> EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in
doAfterBody(),
> then return EVAL_PAGE() in doEndTag().  However, BodyContent has a
protected
> constructor, and no way to set its content.
>
> I want to maintain the functionality gained from Struts-like custom tags,
> while extracting the creation of them in a super-duper momma tag.  Any
help?
>
> Lukas
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org




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


Re: Tags creating Tags

Posted by Lukas Bradley <lu...@somnia.com>.
Mike emailed me this idea last night, and I think it's the best yet.

Brilliant solution, Mike.

Lukas

"Mike Jasnowski" <mj...@bea.com> wrote in message
news:MLEMLKNPCAGCLECPELMICEKHEGAA.mjasnows@bea.com...
> Going from your example, I'm not sure why you even need to subclass a
Struts
> tag to get the output you described. You should be able to code something
> like this on your JSP:
>
> <lukas:myTag lang="en">
>   <html:file property="formFile" styleClass="FormField"/>
> </lukas:myTag>
>
>
> The tag handling flow would look like (similar to what you proposed
> earlier):
>
>  myTag.doStartTag();
>
>  pageContext.getOut().println("<table><tr><td>");
>
>  *include output of body of custom tag here, which might be Struts tags
> which are invoked.
>
>  myTag.doEndTag();
>
>  pageContext.getOut().println("</td></tr></table>");
>
>
>  Which would evaluate to
>
>
>  <table>
>   <tr>
>    <td>
>     <input type="file" name="formFile" value="" class="FormField">
>    </td>
>   </tr>
>  </table>
>
> All this w/o changing or subclassing a Struts tag, the only Custom tag
work
> is myTag.
>
> HTH,
> Mike
>
> -----Original Message-----
> From: Lukas Bradley [mailto:lukas@somnia.com]
> Sent: Sunday, October 26, 2003 7:34 PM
> To: struts-user@jakarta.apache.org
> Cc: taglibs-user@jakarta.apache.org
> Subject: Tags creating Tags
>
>
> Hi all,
>
> Maybe I'm just tired, but the answer to this is not to be found.  I could
me
> making this harder than it is, or something might be right in front of me,
> and I don't see it.
>
> What I want is a custom tag that creates other custom tags.  Here is a
> simple example:
>
> <lukas:myTag lang="en" />
>
> Should produce something like this:
>
> <table>
>   <tr><td>English</td></tr>
>   <tr><td><html:file property="formFile"
styleClass="FormField"/></td></tr>
>    <!-- Imagine a lot more custom tags here -->
> </table>
>
> Which should then evaluate to:
>
> <table>
>   <tr><td>English</td></tr>
>   <tr><td><input type="file" name="formFile" value=""
> class="FormField"></td></tr>
>    <!-- Imagine a lot more custom tags rendering here. -->
> </table>
>
> I've thought about trying to extend BodyTagSupport, return
> EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in
doAfterBody(),
> then return EVAL_PAGE() in doEndTag().  However, BodyContent has a
protected
> constructor, and no way to set its content.
>
> I want to maintain the functionality gained from Struts-like custom tags,
> while extracting the creation of them in a super-duper momma tag.  Any
help?
>
> Lukas
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-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: Tags creating Tags

Posted by Mike Jasnowski <mj...@bea.com>.
Going from your example, I'm not sure why you even need to subclass a Struts
tag to get the output you described. You should be able to code something
like this on your JSP:

<lukas:myTag lang="en">
  <html:file property="formFile" styleClass="FormField"/>
</lukas:myTag>


The tag handling flow would look like (similar to what you proposed
earlier):

 myTag.doStartTag();

 pageContext.getOut().println("<table><tr><td>");

 *include output of body of custom tag here, which might be Struts tags
which are invoked.

 myTag.doEndTag();

 pageContext.getOut().println("</td></tr></table>");


 Which would evaluate to


 <table>
  <tr>
   <td>
    <input type="file" name="formFile" value="" class="FormField">
   </td>
  </tr>
 </table>

All this w/o changing or subclassing a Struts tag, the only Custom tag work
is myTag.

HTH,
Mike

-----Original Message-----
From: Lukas Bradley [mailto:lukas@somnia.com]
Sent: Sunday, October 26, 2003 7:34 PM
To: struts-user@jakarta.apache.org
Cc: taglibs-user@jakarta.apache.org
Subject: Tags creating Tags


Hi all,

Maybe I'm just tired, but the answer to this is not to be found.  I could me
making this harder than it is, or something might be right in front of me,
and I don't see it.

What I want is a custom tag that creates other custom tags.  Here is a
simple example:

<lukas:myTag lang="en" />

Should produce something like this:

<table>
  <tr><td>English</td></tr>
  <tr><td><html:file property="formFile" styleClass="FormField"/></td></tr>
   <!-- Imagine a lot more custom tags here -->
</table>

Which should then evaluate to:

<table>
  <tr><td>English</td></tr>
  <tr><td><input type="file" name="formFile" value=""
class="FormField"></td></tr>
   <!-- Imagine a lot more custom tags rendering here. -->
</table>

I've thought about trying to extend BodyTagSupport, return
EVAL_BODY_BUFFERED in doStartTag(), modify the bodyContent in doAfterBody(),
then return EVAL_PAGE() in doEndTag().  However, BodyContent has a protected
constructor, and no way to set its content.

I want to maintain the functionality gained from Struts-like custom tags,
while extracting the creation of them in a super-duper momma tag.  Any help?

Lukas




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



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