You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/08/14 04:54:33 UTC

Veltag JSP Taglib

Tonight I committed into the contrib section of CVS a mini-project
called 'Veltag' which is a JSP taglib that allows you to use VTL within
a JSP page.  I also added some documentation to the Velocity site under
'Tools', titled 'IT Manager wants JSP?'.  The documentation isn't
complete, but I have been playing with this for quite some time, and I
didn't want to put off committing it any longer.

This taglib allows you to put VTL right in your JSP pages :

<%@ taglib uri="/WEB-INF/veltag.tld" prefix="vel" %>

<html>
<head>
  <title> Velocity! </title>
</head>

<jsp:useBean id="mybean"  class="GeirBean" />

<body>
    <vel:velocity strictaccess="true">

         #set($mybean = $scopetool.getPageScope("mybean"))

         #if(true)
            this is true!
         #end

         #foreach($item in $mybean.array) 
             $item <br>
         #end
     </vel:velocity>
</body>
</html>

JSP experts : if there are any problems with my JSP or taglib
nomenclature or setup, I would love to know about it.  My JSP is kinda
weak :)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Veltag JSP Taglib

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
David Rees wrote:
> 
> On Tue, Aug 14, 2001 at 05:27:05AM -0400, Geir Magnusson Jr. wrote:
> >
> > Just for the public record, this was done in total seriousness, and I
> > intend to seriously support it either here, in taglibs, or elsewhere
> > Really.  In my limited travels, I have seen a few cases where the usual
> > bromides about standards, lots of Wrox books, ease of hiring resources,
> > etc led to decisions to use JSP, and then watched as people faced trying
> > to cheaply access their existing Java business objects.  (I have seen
> > two clients investigate and/or start using JSP to then backup to
> > WebMacro and then Velocity, or Velocity directly...)
> >
> > If nothing else, allowing you to do access your objects directly
> >
> > <vel:velocity strictaccess="true">
> >
> >    #set($mybean = $scopetool.getPageScope("mybean"))
> >
> >    <ul>
> >    #foreach( $element in $mybean.getTree("blue").sort() )
> >       <li>$element
> >    #end
> >    </ul>
> >
> > </vel:velocity>
> >
> > seems tremendous. (I am sure I don't have to sell this here :)
> >
> > Yes, it's true that this does give you a migration path choice - you
> > either expand the contents between the <vel:velocity> tags or contract
> > them - and I think choice is good.
> 
> This is totally sweet, thanks for checking this in!  I hope to evaluate this
> and test it shortly, it should let us get some Velocity on our pages quickly.
> Have you tested to see what type of performance hit Velocity takes in this
> implementation?

No, not yet.  I will get a few taglibs so I can get the same
functionality, and try it.  I also want to get the WebWork(?) test stuff
that Rickard was quoting and post the results.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Veltag JSP Taglib

Posted by David Rees <dr...@runt.ebetinc.com>.
On Tue, Aug 14, 2001 at 05:27:05AM -0400, Geir Magnusson Jr. wrote:
> 
> Just for the public record, this was done in total seriousness, and I
> intend to seriously support it either here, in taglibs, or elsewhere 
> Really.  In my limited travels, I have seen a few cases where the usual
> bromides about standards, lots of Wrox books, ease of hiring resources,
> etc led to decisions to use JSP, and then watched as people faced trying
> to cheaply access their existing Java business objects.  (I have seen
> two clients investigate and/or start using JSP to then backup to
> WebMacro and then Velocity, or Velocity directly...)
> 
> If nothing else, allowing you to do access your objects directly
> 
> <vel:velocity strictaccess="true">
> 
>    #set($mybean = $scopetool.getPageScope("mybean"))
> 
>    <ul>
>    #foreach( $element in $mybean.getTree("blue").sort() )
>       <li>$element
>    #end
>    </ul>
>  
> </vel:velocity>
> 
> seems tremendous. (I am sure I don't have to sell this here :)
> 
> Yes, it's true that this does give you a migration path choice - you
> either expand the contents between the <vel:velocity> tags or contract
> them - and I think choice is good.

This is totally sweet, thanks for checking this in!  I hope to evaluate this
and test it shortly, it should let us get some Velocity on our pages quickly. 
Have you tested to see what type of performance hit Velocity takes in this
implementation?

Thanks,
Dave

Re: Veltag JSP Taglib

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"Geir Magnusson Jr." wrote:
> 
> Attila Szegedi wrote:
> >
> > A brilliant example of the Trojan horse principle. Now you can use Velocity,
> > tell your manager it's JSP, and don't even have to lie. Ideas like this
> > require some virtuosity  - and a good deal of humor as well.
> 
> I'm going to fess up to 'humor'.  I was continuously chuckling...
> 
> And lets not call it a 'Trojan horse'.  'Migration path' shall be the
> term :) as in
> 
> "It's a J2EE spec-compliant migration path to leverage new technologies
> while minimizing integration risk."
> 
> <or make up your own business blather...>
> 

Just for the public record, this was done in total seriousness, and I
intend to seriously support it either here, in taglibs, or elsewhere 
Really.  In my limited travels, I have seen a few cases where the usual
bromides about standards, lots of Wrox books, ease of hiring resources,
etc led to decisions to use JSP, and then watched as people faced trying
to cheaply access their existing Java business objects.  (I have seen
two clients investigate and/or start using JSP to then backup to
WebMacro and then Velocity, or Velocity directly...)

If nothing else, allowing you to do access your objects directly

<vel:velocity strictaccess="true">

   #set($mybean = $scopetool.getPageScope("mybean"))

   <ul>
   #foreach( $element in $mybean.getTree("blue").sort() )
      <li>$element
   #end
   </ul>
 
</vel:velocity>

seems tremendous. (I am sure I don't have to sell this here :)

Yes, it's true that this does give you a migration path choice - you
either expand the contents between the <vel:velocity> tags or contract
them - and I think choice is good.


-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Veltag JSP Taglib

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Attila Szegedi wrote:
> 
> A brilliant example of the Trojan horse principle. Now you can use Velocity,
> tell your manager it's JSP, and don't even have to lie. Ideas like this
> require some virtuosity  - and a good deal of humor as well.

I'm going to fess up to 'humor'.  I was continuously chuckling...  

And lets not call it a 'Trojan horse'.  'Migration path' shall be the
term :) as in 

"It's a J2EE spec-compliant migration path to leverage new technologies
while minimizing integration risk."

<or make up your own business blather...>

> 
> Frankly, this idea is so good I'm more than tempted to stea-- I meant,
> borrow it and reimplement it in Freemarker.

Please do. :)

geir

 
> Attila.
> 
> ----- Original Message -----
> From: "Geir Magnusson Jr." <ge...@optonline.net>
> To: "velocity-user" <ve...@jakarta.apache.org>
> Sent: 2001. augusztus 13. 19:54
> Subject: Veltag JSP Taglib
> 
> > Tonight I committed into the contrib section of CVS a mini-project
> > called 'Veltag' which is a JSP taglib that allows you to use VTL within
> > a JSP page.  I also added some documentation to the Velocity site under
> > 'Tools', titled 'IT Manager wants JSP?'.  The documentation isn't
> > complete, but I have been playing with this for quite some time, and I
> > didn't want to put off committing it any longer.
> >
> > This taglib allows you to put VTL right in your JSP pages :
> >
> > <%@ taglib uri="/WEB-INF/veltag.tld" prefix="vel" %>
> >
> > <html>
> > <head>
> >   <title> Velocity! </title>
> > </head>
> >
> > <jsp:useBean id="mybean"  class="GeirBean" />
> >
> > <body>
> >     <vel:velocity strictaccess="true">
> >
> >          #set($mybean = $scopetool.getPageScope("mybean"))
> >
> >          #if(true)
> >             this is true!
> >          #end
> >
> >          #foreach($item in $mybean.array)
> >              $item <br>
> >          #end
> >      </vel:velocity>
> > </body>
> > </html>
> >
> > JSP experts : if there are any problems with my JSP or taglib
> > nomenclature or setup, I would love to know about it.  My JSP is kinda
> > weak :)
> >
> > geir
> >
> > --
> > Geir Magnusson Jr.                           geirm@optonline.net
> > System and Software Consulting
> > Developing for the web?  See http://jakarta.apache.org/velocity/
> > Well done is better than well said - New England Proverb
> >

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Veltag JSP Taglib

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/14/01 8:52 AM, "Attila Szegedi" <sz...@freemail.hu> wrote:

> Frankly, this idea is so good I'm more than tempted to stea-- I meant,
> borrow it and reimplement it in Freemarker.
> 
> Attila.

I highly suggest that you do.

-jon


Re: Veltag JSP Taglib

Posted by Attila Szegedi <sz...@freemail.hu>.
A brilliant example of the Trojan horse principle. Now you can use Velocity,
tell your manager it's JSP, and don't even have to lie. Ideas like this
require some virtuosity  - and a good deal of humor as well.

Frankly, this idea is so good I'm more than tempted to stea-- I meant,
borrow it and reimplement it in Freemarker.

Attila.

----- Original Message -----
From: "Geir Magnusson Jr." <ge...@optonline.net>
To: "velocity-user" <ve...@jakarta.apache.org>
Sent: 2001. augusztus 13. 19:54
Subject: Veltag JSP Taglib


> Tonight I committed into the contrib section of CVS a mini-project
> called 'Veltag' which is a JSP taglib that allows you to use VTL within
> a JSP page.  I also added some documentation to the Velocity site under
> 'Tools', titled 'IT Manager wants JSP?'.  The documentation isn't
> complete, but I have been playing with this for quite some time, and I
> didn't want to put off committing it any longer.
>
> This taglib allows you to put VTL right in your JSP pages :
>
> <%@ taglib uri="/WEB-INF/veltag.tld" prefix="vel" %>
>
> <html>
> <head>
>   <title> Velocity! </title>
> </head>
>
> <jsp:useBean id="mybean"  class="GeirBean" />
>
> <body>
>     <vel:velocity strictaccess="true">
>
>          #set($mybean = $scopetool.getPageScope("mybean"))
>
>          #if(true)
>             this is true!
>          #end
>
>          #foreach($item in $mybean.array)
>              $item <br>
>          #end
>      </vel:velocity>
> </body>
> </html>
>
> JSP experts : if there are any problems with my JSP or taglib
> nomenclature or setup, I would love to know about it.  My JSP is kinda
> weak :)
>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> Well done is better than well said - New England Proverb
>


Re: Veltag JSP Taglib

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
David Rees wrote:
> 
> On Thu, Aug 16, 2001 at 12:48:42PM -0700, Tim Colson wrote:
> >
> > Based on the docs (geez man, you're a machine!), this is probably a lame JSP
> > question, but with the auto-scope fetching and assuming the servlet stuck a
> > bean into the request/session/app scope, would the <jsp:useBean> be
> > required?
> >
> > <jsp:useBean id="mybean"  class="GeirBean" />
> >  <vel:velocity>
> >     <!-- just access by id - the context -->
> >     <!-- will find it automatically      -->
> >     #foreach($item in $mybean.array)
> >        $item <br>
> >     #end
> > </vel:velocity>
> 
> As I understand it, you don't need the <jsp:useBean> if the bean is already
> in the context somewhere: 

That's right - but be careful of the word 'context', because the
conventional VelocityContext isn't accessable - it's generated by the
taglib.  A better term would be scope (page, request, session or app).

> Meaning if the bean is in the application,
> session, page or request scope the velocity taglib will find it.
> However, if it's not there, you will need to stick it there by using a
> <jsp:useBean> in a JSP or the equivalent in a servlet.

Yep.
 

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

Re: Veltag JSP Taglib

Posted by David Rees <dr...@runt.ebetinc.com>.
On Thu, Aug 16, 2001 at 12:48:42PM -0700, Tim Colson wrote:
> 
> Based on the docs (geez man, you're a machine!), this is probably a lame JSP
> question, but with the auto-scope fetching and assuming the servlet stuck a
> bean into the request/session/app scope, would the <jsp:useBean> be
> required?
> 
> <jsp:useBean id="mybean"  class="GeirBean" />
>  <vel:velocity>
>     <!-- just access by id - the context -->
>     <!-- will find it automatically      -->
>     #foreach($item in $mybean.array)
>        $item <br>
>     #end
> </vel:velocity>

As I understand it, you don't need the <jsp:useBean> if the bean is already
in the context somewhere:  Meaning if the bean is in the application,
session, page or request scope the velocity taglib will find it.
However, if it's not there, you will need to stick it there by using a
<jsp:useBean> in a JSP or the equivalent in a servlet.

Please correct me if I'm wrong, Geir.  ;-)

-Dave

RE: Veltag JSP Taglib

Posted by Tim Colson <tc...@cisco.com>.
> Nope - totally independent.  The Struts effort is just to make it easy
> to use pure Velocity pages in the Struts environment, with or without
> JSPs in the same application.
Excellant - still looking forward to that, but in the meanwhile, some
migration can take place with the VELTAG - which is working splendidly.

> The following depends on what you mean by 'as if', but yes, except that
Yep - it's working just as expected. Quite nicely too. ;-)

Curious, how would we setup custom properties for the velocity engine while
using the TAGLIB?
Example: global macro file, custom logger

Cheers,
Timothy



Re: Veltag JSP Taglib

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tim Colson wrote:
> 
> Geir -
> 
> > This taglib allows you to put VTL right in your JSP pages :
> Crafty. Brilliant. Bravo!!
> 
> So was this the result of the "rekindled Struts" effort - or is there more
> fun to come?

Nope - totally independent.  The Struts effort is just to make it easy
to use pure Velocity pages in the Struts environment, with or without
JSPs in the same application.

> 
> Based on the docs (geez man, you're a machine!), this is probably a lame JSP
> question, but with the auto-scope fetching and assuming the servlet stuck a
> bean into the request/session/app scope, would the <jsp:useBean> be
> required?
> 
> <jsp:useBean id="mybean"  class="GeirBean" />
>  <vel:velocity>
>     <!-- just access by id - the context -->
>     <!-- will find it automatically      -->
>     #foreach($item in $mybean.array)
>        $item <br>
>     #end
> </vel:velocity>

No - the <jsp:useBean> is there to show you how the bean might have
gotten there, and how the auto-finding context would find it and use it.
 
> Also - assuming the fetch works fine w/o the useBean, should we expect
> Strings to work as if they were stuck into a regular velocity context?

The following depends on what you mean by 'as if', but yes, except that
you don't have the pattern of get/fill context -> choose template ->
render because you are in a JSP.  

The 'as if' might mean that you aren't suggesting to use a regular
context, so you can then ignore everything past the 'except', above.

> ex. request.setAttribute("foo","monkey");
 <vel:velocity>$foo business!</vel:velocity>

Yes, that should work fine.  I am going to use weasel words like
'should' for a while until this is tested better, but indeed that should
work.

> 
> (Btw, that's a roundabout way of implying that it annoys me in a certain
> un-named framework that AFAIK strings must be wrapped into beans so
> <bean:write name="foo" property="value" /> outputs what Velocity would have
> done with just $foo! ;-)

It's not an un-named framework issue, but simply a JSP issue.

geir
 
> Thanks - I plan to try the tag out soon to

Cool!

geir
 
> Tim
> 
> P.S. If I'm just a moron regarding that annoyance, I'd appreciate being
> educated! :-)

Me too - except for the bit about it being un-named framework specific
(as I think it's JSP in general) you are right on...


-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

RE: Veltag JSP Taglib

Posted by Tim Colson <tc...@cisco.com>.
Geir -

> This taglib allows you to put VTL right in your JSP pages :
Crafty. Brilliant. Bravo!!

So was this the result of the "rekindled Struts" effort - or is there more
fun to come?

Based on the docs (geez man, you're a machine!), this is probably a lame JSP
question, but with the auto-scope fetching and assuming the servlet stuck a
bean into the request/session/app scope, would the <jsp:useBean> be
required?

<jsp:useBean id="mybean"  class="GeirBean" />
 <vel:velocity>
    <!-- just access by id - the context -->
    <!-- will find it automatically      -->
    #foreach($item in $mybean.array)
       $item <br>
    #end
</vel:velocity>

Also - assuming the fetch works fine w/o the useBean, should we expect
Strings to work as if they were stuck into a regular velocity context?

ex. request.setAttribute("foo","monkey");
<vel:velocity>$foo business!</vel:velocity>

(Btw, that's a roundabout way of implying that it annoys me in a certain
un-named framework that AFAIK strings must be wrapped into beans so
<bean:write name="foo" property="value" /> outputs what Velocity would have
done with just $foo! ;-)

Thanks - I plan to try the tag out soon to

Tim

P.S. If I'm just a moron regarding that annoyance, I'd appreciate being
educated! :-)


FW: Veltag JSP Taglib

Posted by Jon Stevens <jo...@latchkey.com>.
I love it.

-jon

------ Forwarded Message
From: "Geir Magnusson Jr." <ge...@optonline.net>
Reply-To: velocity-user@jakarta.apache.org
Date: Mon, 13 Aug 2001 22:54:33 -0400
To: velocity-user <ve...@jakarta.apache.org>
Subject: Veltag JSP Taglib

Tonight I committed into the contrib section of CVS a mini-project
called 'Veltag' which is a JSP taglib that allows you to use VTL within
a JSP page.  I also added some documentation to the Velocity site under
'Tools', titled 'IT Manager wants JSP?'.  The documentation isn't
complete, but I have been playing with this for quite some time, and I
didn't want to put off committing it any longer.

This taglib allows you to put VTL right in your JSP pages :

<%@ taglib uri="/WEB-INF/veltag.tld" prefix="vel" %>

<html>
<head>
  <title> Velocity! </title>
</head>

<jsp:useBean id="mybean"  class="GeirBean" />

<body>
    <vel:velocity strictaccess="true">

         #set($mybean = $scopetool.getPageScope("mybean"))

         #if(true)
            this is true!
         #end

         #foreach($item in $mybean.array)
             $item <br>
         #end
     </vel:velocity>
</body>
</html>

JSP experts : if there are any problems with my JSP or taglib
nomenclature or setup, I would love to know about it.  My JSP is kinda
weak :)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Well done is better than well said - New England Proverb

------ End of Forwarded Message


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