You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Attila Szegedi <sz...@freemail.hu> on 2003/01/01 15:07:48 UTC

Re: Mixing Velocity and JSP

If Velocity had a syntax for passing a block of the template to an object in
the context for transforming, it could have support for BodyTags as well
(these are by far most interesting; Struts, OpenSymphony OSCache or SiteMesh
come to mind).

Folks, I swear my only intention mentioning what follows is to help the
original poster find the tool that suits his needs best. I'll mention this
only once and won't descend into lengthy discussions or comparisons. No
flame wars, please. I even sent this message (modulo this sentence) to Geir
for review before posting it here and waited until he gave the green light.

The current CVS HEAD of FreeMarker has its own lightweight JSP runtime
support I wrote around two months ago that can host any JSP taglib when
run in Servlet environment. It is slated for 2.2 release, for which we have
scheduled the first public preview in a next week or two.

A sample of using Struts inside a FM template looks like this:

<#global html=JspTaglibs["/WEB-INF/struts-html.tld"]>
<#global bean=JspTaglibs["/WEB-INF/struts-bean.tld"]>

<html>
  <body>
    <h1><$bean.message key="welcome.title"/></h1>
    <$html.errors/>
    <$html.form action="/query">
      Keyword: <$html.text property="keyword"/><br>
      Exclude: <$html.text property="exclude"/><br>
      <$html.submit value="Send"/>
    </$html.form>
  </body>
</html>

This is equivalent to the following JSP page:

<%@page contentType="text/html;charset=ISO-8859-2" language="java"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<html>
  <body>
    <h1><bean:message key="welcome.title"/></h1>
    <html:errors/>
    <html:form action="/query">
      Keyword: <html:text property="keyword"/><br>
      Exclude: <html:text property="exclude"/><br>
      <html:submit value="Send"/>
    </html:form>
  </body>
</html>

 As I said, Velocity could have similar support as well if it had a notion
of context objects that can process a block of template body and a block
directive that passes its block to such context object.

Attila.

----- Original Message -----
From: "Michael Klem" <mi...@earthlink.net>
To: <ve...@jakarta.apache.org>
Sent: Tuesday, December 31, 2002 5:58 PM
Subject: Mixing Velocity and JSP


> Is it possible to create a Velocity template that also uses JSP tag
> libraries? I am converting a JSP app to use Velocity but a few pages
> use JSP tag libraries. Not sure how I can do this.
> --
>   Michael Klem <kl...@corp.earthlink.net>    626-296-3027
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Mixing Velocity and JSP

Posted by Michael Klem <mi...@earthlink.net>.
Oh cool didn't try that but now I will. Thanks!

>Wednesday, January 1, 2003, 6:52:13 PM, Michael Klem wrote:
>
>>  Actually since my web app was small enough I just converted
>>  everything to use Velocity instead of JSP. My JSP tag library was
>>  simple enough that I just did it all using a Velocity template and
>>  moving some code into the appropriate command class.
>>
>>  The problem with this is that I know lose my welcome pages, as far as
>>  I can tell when I convert all my JSPs to Velocity. I need to figure
>>  out if there is a way to specify a command to be called instead of a
>>  welcome page.[snip]
>
>What do you mean? Say, if the "command" is index.do, and I create a
>real file (does not mater what does that contain), then
>
>     <welcome-file-list>
>         <welcome-file>index.do</welcome-file>
>     </welcome-file-list>
>
>will suddenly work.
>
>--
>Best regards,
>  Daniel Dekany
>
>
>--
>To unsubscribe, e-mail: 
><ma...@jakarta.apache.org>
>For additional commands, e-mail: 
><ma...@jakarta.apache.org>


-- 
  Michael Klem <kl...@corp.earthlink.net>    626-296-3027

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Mixing Velocity and JSP

Posted by Daniel Dekany <dd...@freemail.hu>.
Wednesday, January 1, 2003, 6:52:13 PM, Michael Klem wrote:

> Actually since my web app was small enough I just converted 
> everything to use Velocity instead of JSP. My JSP tag library was 
> simple enough that I just did it all using a Velocity template and 
> moving some code into the appropriate command class.
>
> The problem with this is that I know lose my welcome pages, as far as 
> I can tell when I convert all my JSPs to Velocity. I need to figure 
> out if there is a way to specify a command to be called instead of a 
> welcome page.[snip]

What do you mean? Say, if the "command" is index.do, and I create a
real file (does not mater what does that contain), then

    <welcome-file-list>
        <welcome-file>index.do</welcome-file>
    </welcome-file-list>

will suddenly work.

-- 
Best regards,
 Daniel Dekany


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Mixing Velocity and JSP

Posted by Michael Klem <mi...@earthlink.net>.
Actually since my web app was small enough I just converted 
everything to use Velocity instead of JSP. My JSP tag library was 
simple enough that I just did it all using a Velocity template and 
moving some code into the appropriate command class.

The problem with this is that I know lose my welcome pages, as far as 
I can tell when I convert all my JSPs to Velocity. I need to figure 
out if there is a way to specify a command to be called instead of a 
welcome page. I almost get the impression Turbine would solve this 
problem for me but I do not know enough about it.


>If Velocity had a syntax for passing a block of the template to an object in
>the context for transforming, it could have support for BodyTags as well
>(these are by far most interesting; Struts, OpenSymphony OSCache or SiteMesh
>come to mind).
>
>Folks, I swear my only intention mentioning what follows is to help the
>original poster find the tool that suits his needs best. I'll mention this
>only once and won't descend into lengthy discussions or comparisons. No
>flame wars, please. I even sent this message (modulo this sentence) to Geir
>for review before posting it here and waited until he gave the green light.
>
>The current CVS HEAD of FreeMarker has its own lightweight JSP runtime
>support I wrote around two months ago that can host any JSP taglib when
>run in Servlet environment. It is slated for 2.2 release, for which we have
>scheduled the first public preview in a next week or two.
>
>A sample of using Struts inside a FM template looks like this:
>
><#global html=JspTaglibs["/WEB-INF/struts-html.tld"]>
><#global bean=JspTaglibs["/WEB-INF/struts-bean.tld"]>
>
><html>
>   <body>
>     <h1><$bean.message key="welcome.title"/></h1>
>     <$html.errors/>
>     <$html.form action="/query">
>       Keyword: <$html.text property="keyword"/><br>
>       Exclude: <$html.text property="exclude"/><br>
>       <$html.submit value="Send"/>
>     </$html.form>
>   </body>
></html>
>
>This is equivalent to the following JSP page:
>
><%@page contentType="text/html;charset=ISO-8859-2" language="java"%>
><%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
><%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
>
><html>
>   <body>
>     <h1><bean:message key="welcome.title"/></h1>
>     <html:errors/>
>     <html:form action="/query">
>       Keyword: <html:text property="keyword"/><br>
>       Exclude: <html:text property="exclude"/><br>
>       <html:submit value="Send"/>
>     </html:form>
>   </body>
></html>
>
>  As I said, Velocity could have similar support as well if it had a notion
>of context objects that can process a block of template body and a block
>directive that passes its block to such context object.
>
>Attila.
>
>----- Original Message -----
>From: "Michael Klem" <mi...@earthlink.net>
>To: <ve...@jakarta.apache.org>
>Sent: Tuesday, December 31, 2002 5:58 PM
>Subject: Mixing Velocity and JSP
>
>
>>  Is it possible to create a Velocity template that also uses JSP tag
>>  libraries? I am converting a JSP app to use Velocity but a few pages
>>  use JSP tag libraries. Not sure how I can do this.
>>  --
>>    Michael Klem <kl...@corp.earthlink.net>    626-296-3027
>>
>>  --
>>  To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
>>  For additional commands, e-mail:
><ma...@jakarta.apache.org>
>>
>>
>>
>>
>
>
>--
>To unsubscribe, e-mail: 
><ma...@jakarta.apache.org>
>For additional commands, e-mail: 
><ma...@jakarta.apache.org>


-- 
  Michael Klem <kl...@corp.earthlink.net>    626-296-3027

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>