You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Newsham <ne...@hotu.com> on 2001/03/17 03:20:07 UTC

struts-template tag library vs.

Hi,

What are the differences between using the struts template tag library and
jsp's include action?  What are the advantages and trade-offs of each?

Thanks,

Jim Newsham




RE: struts-template tag library vs.

Posted by Troy Hart <th...@part.net>.
The template custom actions (including "insert", "put", and "get") are
absolutely distinct from the JSP "include" action. I would recommend that
you review the code for the struts-template web application that comes with
struts1.0 beta 1. In a nutshell, the template allows you to define a single
template page that lays out a set of components by referencing the
components by name.

Let's say the following is the contents of a file called
"/somePageLayoutSetup.jsp":
-----------
<%@ taglib uri='/WEB-INF/tlds/struts-template.tld' prefix='template' %>
<template:insert template="/myTemplate.jsp">
	<template:put name="title" content="Some Page Title" direct="true"/>
	<template:put name="header" content="/header.jsp" />
	<template:put name="footer" content="/footer.jsp" />
	<template:put name="main-body" content="/somePage.jsp" />
</template:insert>
-----------

Now then, here is the template, "/myTemplate.jsp":
-----------
<%@ taglib uri='/WEB-INF/tlds/struts-template.tld' prefix='template' %>
<html>
<head>
	<title><template:get name="title" /></title>
</head>
<body>
<table>
	<tr><td><template:get name="header" /></td></tr>
	<tr><td><template:get name="main-body" /></td></tr>
	<tr><td><template:get name="footer" /></td></tr>
</table>
I can also put any static stuff that I desire directly on this layout
template...
</body>
-----------

This is obviously a simple example but it illustrates the point. Namely, you
have a page that references a layout template and "put"s named components
into a context such that the referenced template can "get" at them.
Obviously, the power here is that for any given page on your site you only
need to know what the components of the layout are, not how they are laid
out. When you want to change the way they are laid out you only need to
change the layout JSP (assuming components don't change). The mechanism that
is used by the <jsp:include.../> action is (as I understand) functionally
equivalent to, if not exactly the same as, that used by the <template:get
name=.../> (when the named element was "put" with "direct='false'", which is
the default).

Like I said initially, a review of the "struts-template" web app. will clear
this up for you.

Good luck,

Troy


-----Original Message-----
From: newsham@frodo.hotu.com [mailto:newsham@frodo.hotu.com]On Behalf Of
Jim Newsham
Sent: Monday, March 19, 2001 12:59 PM
To: struts-user@jakarta.apache.org
Subject: Re: struts-template tag library vs. <jsp:include/>



Thank you for your reply, but this didn't really answer my question.  Let me
rephrase.  I am talking about <jsp:include/>, which is a dynamic templating
mechanism, as opposed to <%@ include %>, which is static.  As I understand
it:

<jsp:include/> and <struts-template:*/> are both dynamic templating
mechanisms
-- they are re-evaluated at runtime whenever referenced.  They allow you to
create a template with placeholders for dynamic values which you will supply
at
runtime.  This is where they are similar.  What I'm interested in hearing is
how they differ.

I assume that struts-template offers some improvement over jsp:include,
otherwise it serves no purpose.  So my question is, what does
struts-template
offer as an improvement over jsp:include?  The answer may be as simple as
"it
provides a consistent and readable syntax", or it may be more substantial.

Thank you,

Jim Newsham


Robert Taylor wrote:

> Although it doesn't discuss struts template tag specifically, the J2EE
> BluePrint has a good section on the comparison of JSP includes and using
> templates. I believe it is in section 10.3 where it discuss the Sample
> Application: View.
> http://java.sun.com/j2ee/blueprints/sample_application/view/index.html
>
> HTH,
>
> Robert
>
> > -----Original Message-----
> > From: newsham@frodo.hotu.com [mailto:newsham@frodo.hotu.com]On Behalf Of
> > Jim Newsham
> > Sent: Friday, March 16, 2001 9:20 PM
> > To: struts-user@jakarta.apache.org
> > Subject: struts-template tag library vs. <jsp:include/>
> >
> >
> >
> > Hi,
> >
> > What are the differences between using the struts template tag library
and
> > jsp's include action?  What are the advantages and trade-offs of each?
> >
> > Thanks,
> >
> > Jim Newsham
> >
> >
> >
> >
> >


Re: struts-template tag library vs.

Posted by Jim Newsham <ne...@hotu.com>.
Thank you for your reply, but this didn't really answer my question.  Let me
rephrase.  I am talking about <jsp:include/>, which is a dynamic templating
mechanism, as opposed to <%@ include %>, which is static.  As I understand it:

<jsp:include/> and <struts-template:*/> are both dynamic templating mechanisms
-- they are re-evaluated at runtime whenever referenced.  They allow you to
create a template with placeholders for dynamic values which you will supply at
runtime.  This is where they are similar.  What I'm interested in hearing is
how they differ.

I assume that struts-template offers some improvement over jsp:include,
otherwise it serves no purpose.  So my question is, what does struts-template
offer as an improvement over jsp:include?  The answer may be as simple as "it
provides a consistent and readable syntax", or it may be more substantial.

Thank you,

Jim Newsham


Robert Taylor wrote:

> Although it doesn't discuss struts template tag specifically, the J2EE
> BluePrint has a good section on the comparison of JSP includes and using
> templates. I believe it is in section 10.3 where it discuss the Sample
> Application: View.
> http://java.sun.com/j2ee/blueprints/sample_application/view/index.html
>
> HTH,
>
> Robert
>
> > -----Original Message-----
> > From: newsham@frodo.hotu.com [mailto:newsham@frodo.hotu.com]On Behalf Of
> > Jim Newsham
> > Sent: Friday, March 16, 2001 9:20 PM
> > To: struts-user@jakarta.apache.org
> > Subject: struts-template tag library vs. <jsp:include/>
> >
> >
> >
> > Hi,
> >
> > What are the differences between using the struts template tag library and
> > jsp's include action?  What are the advantages and trade-offs of each?
> >
> > Thanks,
> >
> > Jim Newsham
> >
> >
> >
> >
> >


RE: struts-template tag library vs.

Posted by Robert Taylor <rt...@mulework.com>.
Although it doesn't discuss struts template tag specifically, the J2EE
BluePrint has a good section on the comparison of JSP includes and using
templates. I believe it is in section 10.3 where it discuss the Sample
Application: View.
http://java.sun.com/j2ee/blueprints/sample_application/view/index.html

HTH,

Robert

> -----Original Message-----
> From: newsham@frodo.hotu.com [mailto:newsham@frodo.hotu.com]On Behalf Of
> Jim Newsham
> Sent: Friday, March 16, 2001 9:20 PM
> To: struts-user@jakarta.apache.org
> Subject: struts-template tag library vs. <jsp:include/>
>
>
>
> Hi,
>
> What are the differences between using the struts template tag library and
> jsp's include action?  What are the advantages and trade-offs of each?
>
> Thanks,
>
> Jim Newsham
>
>
>
>
>


RE: struts-template tag library vs.

Posted by Troy Hart <th...@part.net>.
the biggest thing for me is that you limit the potential layout bugs, and
you make it possible to change the layout, site wide, with the editing of a
single file. The alternative (just using <jsp:include.../>) forces you to
replicate the layout framework (typically this includes a set of nested
tables where you set the header, footer, sidebar, and etc...) on every
single jsp page.

Troy


-----Original Message-----
From: newsham@frodo.hotu.com [mailto:newsham@frodo.hotu.com]On Behalf Of
Jim Newsham
Sent: Friday, March 16, 2001 7:20 PM
To: struts-user@jakarta.apache.org
Subject: struts-template tag library vs. <jsp:include/>



Hi,

What are the differences between using the struts template tag library and
jsp's include action?  What are the advantages and trade-offs of each?

Thanks,

Jim Newsham