You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rian Schmidt <ri...@finebrand.com> on 2001/06/21 04:23:57 UTC

Replacing custom tags...

Hi,

Thanks for the suggestions on replacing our custom tags with a utility class
in the context-- seems to work great for replacing empty element type tags
(or a singleton tags).  I've got a refinement to that question that I'd
appreciate some suggestions on.

What is the preferred method to implement something like a body tag?  As an
example, say something like:
<mt:indent depth="3" border="0" class="small-txt">A whole bunch of HTML and
data goes here</mt:indent>
produces something like this:
<table border="0"><tr>
<td>&nbsp;&nbsp;&nbsp;</td><td class="small-txt">A whole bunch of HTML and
data goes here</td>
</tr></table>

I would assume that I could do a Velocimacro, but the "A whole bunch..."
text could really be a whole bunch, making passing it as an argument
unpleasant.  Moreover, our designers, working on Dreamweaver, wouldn't be
able to see the data in its actual place as they can with the custom tag
(Dreamweaver ignores it.)

Is the best option to do something like:
#indent_start(3,0,"small-txt")A whole bunch of HTML and data goes
here#indent_end()

Or is there something along the lines of a body tag that I'm not seeing.

Thanks,
Rian



Re: Replacing custom tags...

Posted by Rian Schmidt <ri...@finebrand.com>.
> This problem stopped me cold in my tracks when I was all hot and
> bothered about converting all taglibs tags to context tools - anything
> extending BodyTag kills you...
>
> I keep thinking about it, but don't have any solutions yet.  It's a nice
> feature in some ways.  (In other ways, its a real horror from an
> implementor stand point and can't be good for performance :)
>
Good.  I'm glad it's not just me.  Agreed that it's a nice feature in some
ways... particularly the named attributes.  Makes it handy for documenting
for the designers and production folks, and it's familiar because of their
experience with ColdFusion custom tags.  On the other hand, they seem to
only be able to deal with a few per project.  Beyond that (i.e., Struts),
they get more confused than they were with plain code in place.

> > Is the best option to do something like:
> > #indent_start(3,0,"small-txt")A whole bunch of HTML and data goes
> > here#indent_end()
> >
> > Or is there something along the lines of a body tag that I'm not seeing.
>
> There's nothing.  It's possible to add a 'body directive' to velocity -
> but it never feels right to do that.  I would think your gui tools
> should be able to indent like that...
>
> I know this is a poor answer...

Not at all.  My example probably implied that indenting was my goal.  It's
not really.  The J2EE application in question uses several body tags, and
that's just one of them.  The reason for using the tag in this particular
case is that it's indenting a threaded discussion list, each posting of
which is an EJB entity that has a "depth" property associated with it.
Otherwise, you're right, we'd just indent it in DW and be done with it.  We
can work around it, but I'm new to Velocity and asking in a more general
sense.

We're currently fighting with a "MVC using JSP" approach on a fairly large
app that works fine but still requires a bunch of casting, curly braces,
exception handling, and so forth in the page.  Speaking of not fun...

Rian


Re: Replacing custom tags...

Posted by Bill Burton <bi...@progress.com>.
Hello,

I've also been thinking about how JSP taglibs could be adapted to use with
Velocity.  Along this line I was wishing for a way to set a block of text
to a variable.  For instance, it would be nice if you could do this:
    #setinline($bodyText)
    ...
    stuff and more stuff
    ...
    #end

which would cause all the text between #setinline() and the corresponding
#end to be saved into $bodyText.  Maybe a better directive name would be
#collect?  Also, could the existing #set directive be modified to work
this way if only a single argument was specified?  Don't know if this is
feasable or not.

Well, it turns out you can do almost the same thing by using a macro with
no parameters:
    #macro(bodyText)
    ...
    stuff and more stuff
    ...
    #end

Then just put #bodyText() where you want the output.  If you really prefer
to store the content in the context, then add this line:
    #set($bodyText = "#bodyText()")
to evaluate the macro into a variable.  That's a bit terse so it would
still be nice to have a new directive for setting inline content into the
context.

Another way no parameter macros can be used is to group related content in
a single file but only loading it once via #parse.  This can make
maintenance easier over having several smaller related files.  For
instance:
    ## navigation.vm
    #macro(navigation_head)
    <script language="JavaScript">
    ...
    </script>
    #end
    #macro(navigation_body)
    ...
    #end
    #macro(body_onload)
    ...
    #end
    #set($body_onload = "#body_onload()")

    ## index.vm
    <html>
    <head>
    #parse("navigation.vm")
    #navigation_head()
    </head>
    <body $body_onload>
    #navigation_body()
    </body>
    </html>

For this scheme to work, you must set the property:
    velocimacro.permissions.allow.inline.local.scope = false
so the macros defined in one file can be used in another.  If for other
reasons this isn't an option, then you can add the #set directive as
described previously to save the contents of the macro in the context.

-Bill

"Geir Magnusson Jr." wrote:
> 
> Rian Schmidt wrote:
> >
> > Hi,
> >
> > Thanks for the suggestions on replacing our custom tags with a utility class
> > in the context-- seems to work great for replacing empty element type tags
> > (or a singleton tags).  I've got a refinement to that question that I'd
> > appreciate some suggestions on.
> >
> > What is the preferred method to implement something like a body tag?  As an
> > example, say something like:
> > <mt:indent depth="3" border="0" class="small-txt">A whole bunch of HTML and
> > data goes here</mt:indent>
> > produces something like this:
> > <table border="0"><tr>
> > <td>&nbsp;&nbsp;&nbsp;</td><td class="small-txt">A whole bunch of HTML and
> > data goes here</td>
> > </tr></table>
> 
> This problem stopped me cold in my tracks when I was all hot and
> bothered about converting all taglibs tags to context tools - anything
> extending BodyTag kills you...
> 
> I keep thinking about it, but don't have any solutions yet.  It's a nice
> feature in some ways.  (In other ways, its a real horror from an
> implementor stand point and can't be good for performance :)
> 
> >
> > I would assume that I could do a Velocimacro, but the "A whole bunch..."
> > text could really be a whole bunch, making passing it as an argument
> > unpleasant.  Moreover, our designers, working on Dreamweaver, wouldn't be
> > able to see the data in its actual place as they can with the custom tag
> > (Dreamweaver ignores it.)
> 
> Yes, that wouldn't be fun.
> 
> > Is the best option to do something like:
> > #indent_start(3,0,"small-txt")A whole bunch of HTML and data goes
> > here#indent_end()
> >
> > Or is there something along the lines of a body tag that I'm not seeing.
> 
> There's nothing.  It's possible to add a 'body directive' to velocity -
> but it never feels right to do that.  I would think your gui tools
> should be able to indent like that...
> 
> I know this is a poor answer...
> 
> geir
> 
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> You have a genius for suggesting things I've come a cropper with!

-- 
Bill Burton, Senior Web Developer
E-mail: billb@progress.com
Address: Progress Software Corporation, 14 Oak Park, Bedford, MA 01730

Re: Replacing custom tags...

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Rian Schmidt wrote:
> 
> Hi,
> 
> Thanks for the suggestions on replacing our custom tags with a utility class
> in the context-- seems to work great for replacing empty element type tags
> (or a singleton tags).  I've got a refinement to that question that I'd
> appreciate some suggestions on.
> 
> What is the preferred method to implement something like a body tag?  As an
> example, say something like:
> <mt:indent depth="3" border="0" class="small-txt">A whole bunch of HTML and
> data goes here</mt:indent>
> produces something like this:
> <table border="0"><tr>
> <td>&nbsp;&nbsp;&nbsp;</td><td class="small-txt">A whole bunch of HTML and
> data goes here</td>
> </tr></table>

This problem stopped me cold in my tracks when I was all hot and
bothered about converting all taglibs tags to context tools - anything
extending BodyTag kills you...

I keep thinking about it, but don't have any solutions yet.  It's a nice
feature in some ways.  (In other ways, its a real horror from an
implementor stand point and can't be good for performance :)

> 
> I would assume that I could do a Velocimacro, but the "A whole bunch..."
> text could really be a whole bunch, making passing it as an argument
> unpleasant.  Moreover, our designers, working on Dreamweaver, wouldn't be
> able to see the data in its actual place as they can with the custom tag
> (Dreamweaver ignores it.)

Yes, that wouldn't be fun.
 
> Is the best option to do something like:
> #indent_start(3,0,"small-txt")A whole bunch of HTML and data goes
> here#indent_end()
> 
> Or is there something along the lines of a body tag that I'm not seeing.

There's nothing.  It's possible to add a 'body directive' to velocity -
but it never feels right to do that.  I would think your gui tools
should be able to indent like that...

I know this is a poor answer...

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!