You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Niall Pemberton <ni...@btInternet.com> on 2001/06/14 02:43:20 UTC

RE: Proposal: Support nested tags where only attributes can be used

For the example you give, the following works just as well in existing
Struts:

In your JSP page:

 <template:insert template="t.jsp">
   <template:put name="pageTitle" direct="true">
      <bean:message key="login.title"/>
   </template:put>
 </template:insert>

 Now, in "t.jsp"....

 <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
 ...
 <h1>Title is <template:get name="pageTitle"/></h1>


Niall


> -----Original Message-----
> From: Dean Wampler [mailto:dwampler@powerhousetechnology.com]
> Sent: 15 June 2001 01:28
> To: struts-dev@jakarta.apache.org
> Cc: Dean Wampler (E-mail)
> Subject: Proposal: Support nested tags where only attributes can be used
>
>
> I'm new to struts, so bear with me.
>
> I have been working with the "bean" and "template" tags. I have
> found that a
> straightforward (if a bit tedious to do...) enhancement would make it much
> easier to construct JSP pages in ways useful for me.  Basically, I would
> like to use nested tags to specify some information to outer tag,
> information that currently is specified only through attributes.
>
> Here's an example.  Suppose I have a JSP page that uses the
> <template:insert> construct:
>
> ...
> <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
> ...
> <template:insert template="t.jsp">
>   <template:put name="pageName" content="login" direct="true"/>
> </template:insert>
>
> Now, in "t.jsp", I would like to use the message tag with the parameter
> "pageName" as a "prefix".  Something that might look like:
>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> ...
> <h1>Title is <bean:message key='<template:get
> name="pageName"/><%=".title"%>'/></h1>
>
> or perhaps
>
> <h1>Title is <bean:message key='<%=<template:get
> name="pageName"/>+".title"%>'/></h1>
>
> There are two problems: (i) this is ugly and not easy to use by most HTML
> designers, (ii) it doesn't work anyway.  By the time the code
> gets compiled
> to a servlet, it appears that the "key='...'" expression ends up "key=''".
> That is, '<template:get name="pageName"/>' is effectively empty.
>
> However, the following message tag structure would solve both problems and
> support the capability I'm after (indentation is
> for clarity...):
>
> <h1>Title is
>   <bean:message>
>     <bean:key>
>       <template:get name="pageName"/>.title
>     </bean:key>
>   </bean:message>
> </h1>
>
> In other words, support nested tags to specify the "key" and perhaps other
> attributes, so that specifying the values of the attributes is more
> flexible.
>
> Many of the "ant" tasks support capabilities like this and it greatly
> enhances the power and flexibility of build files.
>
> I have looked at the code for MessageTag (and others).  This extension is
> straightforward to implement and it can be done in a backwards compatible
> way (that is, the old attribute syntax will still work fine).
>
> I'm willing to implement the changes, but before I do so, I
> wanted to check
> with the rest of you to see if there are any good reasons not to proceed.
>
> Thanks,
> dean
>
> Dean Wampler, Ph.D.
> dwampler@powerhousetechnology.com
> <ma...@powerhousetechnology.com>
> http://www.powerhousetechnology.com/
>
> I want my tombstone to say:
>
>   Unknown Application Error in Dean Wampler.exe.
>   Application Terminated.
>                                                  [OK] [Cancel]
>


RE: Proposal: Support nested tags where only attributes can be used

Posted by Niall Pemberton <ni...@btInternet.com>.
How about a custom tag, which combines <bean:message> and <template:get>
functionality?

For example....

   <h1>Title is <myTaglib:message template="page" suffix=".title"/></h1>

I've attached a tag like this.


Niall



> -----Original Message-----
> From: Dean Wampler [mailto:dwampler@powerhousetechnology.com]
> Sent: 15 June 2001 17:28
> To: 'Niall Pemberton'; struts-dev@jakarta.apache.org
> Cc: Dean Wampler (E-mail)
> Subject: RE: Proposal: Support nested tags where only attributes can be
> used
>
> I wanted to avoid writing stuff like
>
>   <template:insert template="t.jsp">
>     <template:put name="pageTitle" direct="true">
>        <bean:message key="login.title"/>
>     </template:put>
>     <template:put name="pageThis" direct="true">
>        <bean:message key="login.this"/>
>     </template:put>
>     <template:put name="pageThat" direct="true">
>        <bean:message key="login.that"/>
>     </template:put>
>     <template:put name="pageTheOther" direct="true">
>        <bean:message key="login.theOther"/>
>     </template:put>
>     ...
>   </template:insert>
>
> for every single page when I could just define one thing for each page:
>
>   <template:insert template="t.jsp">
>     <template:put name="page" content="login" direct="true"/>
>   </template:insert>
>
> and have the template page "t.jsp" construct all the other items
> dynamically.
>

RE: Proposal: Support nested tags where only attributes can be used

Posted by Dean Wampler <dw...@powerhousetechnology.com>.

> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@btInternet.com]
> Sent: Wednesday, June 13, 2001 6:19 PM
> To: struts-dev@jakarta.apache.org; dwampler@powerhousetechnology.com
> Subject: RE: Proposal: Support nested tags where only
> attributes can be
> used
>
>
> I dont really get what your saying. In your template (i.e.
> t.jsp) you define
> the formatting for the common look and feel of all your
> pages, for example
> page titles, a side bar and footers. If on some pages you
> don't need all of
> them you just leave them out - for example if you didn't need
> a footer then
> don't do a <template:get> for it on your jsp page - it still
> works fine.

Let me clarify a bit.  I expect to have two, maybe three, templates, for two
or three different types of pages.  For example, help pages will look
different than "regular" pages, administrator pages will look different than
regular-user pages, etc.  Within these page groups, I expect to have maybe
5-10 pages.  I wanted to avoid writing stuff like

  <template:insert template="t.jsp">
    <template:put name="pageTitle" direct="true">
       <bean:message key="login.title"/>
    </template:put>
    <template:put name="pageThis" direct="true">
       <bean:message key="login.this"/>
    </template:put>
    <template:put name="pageThat" direct="true">
       <bean:message key="login.that"/>
    </template:put>
    <template:put name="pageTheOther" direct="true">
       <bean:message key="login.theOther"/>
    </template:put>
    ...
  </template:insert>

for every single page when I could just define one thing for each page:

  <template:insert template="t.jsp">
    <template:put name="page" content="login" direct="true"/>
  </template:insert>

and have the template page "t.jsp" construct all the other items
dynamically.

HOWEVER, after thinking about it a bit, I've decided that maybe this
approach is too clever, because the stuff you end up doing, like

  <h1>Title is
    <bean:message>
      <bean:key>
        <template:get name="page"/>.title
      </bean:key>
    </bean:message>
  </h1>

isn't so easy to read, is it?  Perhaps the "wasted" effort of all those
<template:put>'s isn't so bad if you get a cleaner t.jsp file with
statements like

  <h1>title is <bean:message key="pageTitle"/></h1>

instead.

So, you're original suggestion of using

    <template:put name="pageTitle" direct="true">
       <bean:message key="login.title"/>
    </template:put>

actually solved the insurmountable problems I had, for which I thank you.  I
think I'll shelve my proposed enhancement for now, unless others are really
interested in it.


dean

> (deleted) ...


RE: Proposal: Support nested tags where only attributes can be used

Posted by Niall Pemberton <ni...@btInternet.com>.
I dont really get what your saying. In your template (i.e. t.jsp) you define
the formatting for the common look and feel of all your pages, for example
page titles, a side bar and footers. If on some pages you don't need all of
them you just leave them out - for example if you didn't need a footer then
don't do a <template:get> for it on your jsp page - it still works fine.

If you have specific messages unique to a page them just put them straight
on the page - if you want to prefix them with the page name then it seems
easier to me to just specify it straight in <bean:message
key="pagename.something"> format.

Personally we don't tie our messages to pages, more to the business area,
that way they're often re-used among pages.

I don't know if this is useful to you because I didn't really get what your
trying to resolve.

Niall

> -----Original Message-----
> From: Dean Wampler [mailto:dwampler@powerhousetechnology.com]
> Sent: 15 June 2001 01:57
> To: struts-dev@jakarta.apache.org
> Subject: RE: Proposal: Support nested tags where only attributes can be
> used
>
>
> Interesting!  I didn't know that.  Certainly that would help.
> It's actually
> another example of the kind of flexibility I'm thinking about.
>
> One disadvantage, though.  It requires that the "outer" page know all the
> messages the inner page wants to use.  I would rather keep this
> coupling to
> a minimum (e.g., just pass the "prefix", like I've shown), especially if I
> have lots of similar outer pages (and I will...).  This way, if I add and
> use a new message or resource in the inner page I don't have to add
> corresponding tags to the outer pages, too.
>
> Thanks,
> dean
>
> > -----Original Message-----
> > From: Niall Pemberton [mailto:niall.pemberton@btInternet.com]
> > Sent: Wednesday, June 13, 2001 5:43 PM
> > To: struts-dev@jakarta.apache.org; dwampler@powerhousetechnology.com
> > Subject: RE: Proposal: Support nested tags where only
> > attributes can be
> > used
> >
> >
> > For the example you give, the following works just as well in existing
> > Struts:
> >
> > In your JSP page:
> >
> >  <template:insert template="t.jsp">
> >    <template:put name="pageTitle" direct="true">
> >       <bean:message key="login.title"/>
> >    </template:put>
> >  </template:insert>
> >
> >  Now, in "t.jsp"....
> >
> >  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> >  ...
> >  <h1>Title is <template:get name="pageTitle"/></h1>
> >
> >
> > Niall
> >
> >
> > > -----Original Message-----
> > > From: Dean Wampler [mailto:dwampler@powerhousetechnology.com]
> > > Sent: 15 June 2001 01:28
> > > To: struts-dev@jakarta.apache.org
> > > Cc: Dean Wampler (E-mail)
> > > Subject: Proposal: Support nested tags where only
> > attributes can be used
> > >
> > >
> > > I'm new to struts, so bear with me.
> > >
> > > I have been working with the "bean" and "template" tags. I have
> > > found that a
> > > straightforward (if a bit tedious to do...) enhancement
> > would make it much
> > > easier to construct JSP pages in ways useful for me.
> > Basically, I would
> > > like to use nested tags to specify some information to outer tag,
> > > information that currently is specified only through attributes.
> > >
> > > Here's an example.  Suppose I have a JSP page that uses the
> > > <template:insert> construct:
> > >
> > > ...
> > > <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
> > > ...
> > > <template:insert template="t.jsp">
> > >   <template:put name="pageName" content="login" direct="true"/>
> > > </template:insert>
> > >
> > > Now, in "t.jsp", I would like to use the message tag with
> > the parameter
> > > "pageName" as a "prefix".  Something that might look like:
> > >
> > > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> > > ...
> > > <h1>Title is <bean:message key='<template:get
> > > name="pageName"/><%=".title"%>'/></h1>
> > >
> > > or perhaps
> > >
> > > <h1>Title is <bean:message key='<%=<template:get
> > > name="pageName"/>+".title"%>'/></h1>
> > >
> > > There are two problems: (i) this is ugly and not easy to
> > use by most HTML
> > > designers, (ii) it doesn't work anyway.  By the time the code
> > > gets compiled
> > > to a servlet, it appears that the "key='...'" expression
> > ends up "key=''".
> > > That is, '<template:get name="pageName"/>' is effectively empty.
> > >
> > > However, the following message tag structure would solve
> > both problems and
> > > support the capability I'm after (indentation is
> > > for clarity...):
> > >
> > > <h1>Title is
> > >   <bean:message>
> > >     <bean:key>
> > >       <template:get name="pageName"/>.title
> > >     </bean:key>
> > >   </bean:message>
> > > </h1>
> > >
> > > In other words, support nested tags to specify the "key"
> > and perhaps other
> > > attributes, so that specifying the values of the attributes is more
> > > flexible.
> > >
> > > Many of the "ant" tasks support capabilities like this and
> > it greatly
> > > enhances the power and flexibility of build files.
> > >
> > > I have looked at the code for MessageTag (and others).
> > This extension is
> > > straightforward to implement and it can be done in a
> > backwards compatible
> > > way (that is, the old attribute syntax will still work fine).
> > >
> > > I'm willing to implement the changes, but before I do so, I
> > > wanted to check
> > > with the rest of you to see if there are any good reasons
> > not to proceed.
> > >
> > > Thanks,
> > > dean
> > >
> > > Dean Wampler, Ph.D.
> > > dwampler@powerhousetechnology.com
> > > <ma...@powerhousetechnology.com>
> > > http://www.powerhousetechnology.com/
> > >
> > > I want my tombstone to say:
> > >
> > >   Unknown Application Error in Dean Wampler.exe.
> > >   Application Terminated.
> > >                                                  [OK] [Cancel]
> > >
> >
> >
>


RE: Proposal: Support nested tags where only attributes can be used

Posted by Dean Wampler <dw...@powerhousetechnology.com>.
Interesting!  I didn't know that.  Certainly that would help. It's actually
another example of the kind of flexibility I'm thinking about.

One disadvantage, though.  It requires that the "outer" page know all the
messages the inner page wants to use.  I would rather keep this coupling to
a minimum (e.g., just pass the "prefix", like I've shown), especially if I
have lots of similar outer pages (and I will...).  This way, if I add and
use a new message or resource in the inner page I don't have to add
corresponding tags to the outer pages, too.

Thanks,
dean

> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@btInternet.com]
> Sent: Wednesday, June 13, 2001 5:43 PM
> To: struts-dev@jakarta.apache.org; dwampler@powerhousetechnology.com
> Subject: RE: Proposal: Support nested tags where only
> attributes can be
> used
>
>
> For the example you give, the following works just as well in existing
> Struts:
>
> In your JSP page:
>
>  <template:insert template="t.jsp">
>    <template:put name="pageTitle" direct="true">
>       <bean:message key="login.title"/>
>    </template:put>
>  </template:insert>
>
>  Now, in "t.jsp"....
>
>  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
>  ...
>  <h1>Title is <template:get name="pageTitle"/></h1>
>
>
> Niall
>
>
> > -----Original Message-----
> > From: Dean Wampler [mailto:dwampler@powerhousetechnology.com]
> > Sent: 15 June 2001 01:28
> > To: struts-dev@jakarta.apache.org
> > Cc: Dean Wampler (E-mail)
> > Subject: Proposal: Support nested tags where only
> attributes can be used
> >
> >
> > I'm new to struts, so bear with me.
> >
> > I have been working with the "bean" and "template" tags. I have
> > found that a
> > straightforward (if a bit tedious to do...) enhancement
> would make it much
> > easier to construct JSP pages in ways useful for me.
> Basically, I would
> > like to use nested tags to specify some information to outer tag,
> > information that currently is specified only through attributes.
> >
> > Here's an example.  Suppose I have a JSP page that uses the
> > <template:insert> construct:
> >
> > ...
> > <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
> > ...
> > <template:insert template="t.jsp">
> >   <template:put name="pageName" content="login" direct="true"/>
> > </template:insert>
> >
> > Now, in "t.jsp", I would like to use the message tag with
> the parameter
> > "pageName" as a "prefix".  Something that might look like:
> >
> > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> > ...
> > <h1>Title is <bean:message key='<template:get
> > name="pageName"/><%=".title"%>'/></h1>
> >
> > or perhaps
> >
> > <h1>Title is <bean:message key='<%=<template:get
> > name="pageName"/>+".title"%>'/></h1>
> >
> > There are two problems: (i) this is ugly and not easy to
> use by most HTML
> > designers, (ii) it doesn't work anyway.  By the time the code
> > gets compiled
> > to a servlet, it appears that the "key='...'" expression
> ends up "key=''".
> > That is, '<template:get name="pageName"/>' is effectively empty.
> >
> > However, the following message tag structure would solve
> both problems and
> > support the capability I'm after (indentation is
> > for clarity...):
> >
> > <h1>Title is
> >   <bean:message>
> >     <bean:key>
> >       <template:get name="pageName"/>.title
> >     </bean:key>
> >   </bean:message>
> > </h1>
> >
> > In other words, support nested tags to specify the "key"
> and perhaps other
> > attributes, so that specifying the values of the attributes is more
> > flexible.
> >
> > Many of the "ant" tasks support capabilities like this and
> it greatly
> > enhances the power and flexibility of build files.
> >
> > I have looked at the code for MessageTag (and others).
> This extension is
> > straightforward to implement and it can be done in a
> backwards compatible
> > way (that is, the old attribute syntax will still work fine).
> >
> > I'm willing to implement the changes, but before I do so, I
> > wanted to check
> > with the rest of you to see if there are any good reasons
> not to proceed.
> >
> > Thanks,
> > dean
> >
> > Dean Wampler, Ph.D.
> > dwampler@powerhousetechnology.com
> > <ma...@powerhousetechnology.com>
> > http://www.powerhousetechnology.com/
> >
> > I want my tombstone to say:
> >
> >   Unknown Application Error in Dean Wampler.exe.
> >   Application Terminated.
> >                                                  [OK] [Cancel]
> >
>
>