You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "T. K. Chris" <ch...@yahoo.fr> on 2004/10/23 10:07:04 UTC

Mixing JSP and velocity

Hi,
 
I have previously developed my web pages using JSP.
After discovering velocity, I would like to migrate my pages into velocity.
I can not envisage that since the number of pages is important.
At this time, my page contains Struts and JSTL tags.

 
My questions:
1- Is there possible to mix velocity and velocity in the same page?
2- So How can I configure my application in order to use velocity within a JSP page.
 
My purpose being to replace some (but not all) complicated JSP rendering with velocity tags.
 
Thanks for your reply.

		
---------------------------------
Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
Créez votre Yahoo! Mail

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis.Téléchargez GRATUITEMENT ici !

RE: Mixing JSP and velocity

Posted by Tim Colson <tc...@cisco.com>.
TK -
> Concerning VelocityViewServlet I have a problem with its 
> setting in the web.xml file :
> <!-- Map *.vm files to Velocity -->
> <servlet-mapping>
>   <servlet-name>velocity</servlet-name>
>   <url-pattern>*.vm</url-pattern>
> </servlet-mapping>

> I already have a setting of my actionServlet:

Not a problem. VelocityViewServlet is -not- handling the *.do actions.
Those actions go to the Struts Controller. 

Look at this diagram:
http://jakarta.apache.org/velocity/tools/struts/

When the controller is "done" -> it hands off to *.jsp which is handled by
JASPER, the JSP processor.

One easy way to transition from jsp to vm is to simply change the mapping
forwards in struts-config.xml -> send one single mapping to a foo.vm file
instead of foo.jsp.

In this way, you can convert one View at a time from JSP to VM. They can
operate in the same webapp. You can even have two forwards, on JSP, one VM. 

<action path="/editComponent"
 type="org.foo.strutsactions.EditComponentAction">
 <forward name="success"          path="/page/editComponent.jsp"/>
 <forward name="success_velocity" path="/page/editComponent.vm"/>
</action>


If you need to have JSP and want to embed Velocity templates -inside- the
JSP...then you'll have to use Veltag which embeds a velocity engine inside a
JSP tag library. I've used it, but I must say I prefer to just switch over
100% to VM :-)

Cheers,
Tim





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


Re: Mixing JSP and velocity

Posted by "T. K. Chris" <ch...@yahoo.fr>.
Hi,,
Thanks again, your explanations are enough clear.
I now understand the real signification of velocity tools.
Concerning VelocityViewServlet I have a problem with its setting in the web.xml file :
<!-- Map *.vm files to Velocity -->
<servlet-mapping>
  <servlet-name>velocity</servlet-name>
  <url-pattern>*.vm</url-pattern>
</servlet-mapping>
 
I already have a setting of my actionServlet:
    <servlet>
        <servlet-name>Action</servlet-name>
        <servlet-class>com.inetpsa.fwk.struts.action.ActionServlet</servlet-class>
        ......
    </servlet>
with the following servlet mapping:
    <servlet-mapping>
        <servlet-name>FwkAction</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
As I stated earlier, I have a large package of Jsp files. So It is not realistic to rename them as *.vm files since our people are not yet familiar with that.
My Questions:
1.)It sounds as using VelocityViewServlet suppose (according to the mapping) that my "*.jsp" being renamed into "*vm" files. Am I right?
2.)By keeping my files as *.jsp, How can I add the VelocityViewServlet features and by the way, use the velocity Tools efficiently?
 
Best regards,
Chris.

Shinobu Kawai <sh...@gmail.com> wrote:
Hi Chris,

> Thanks for your reply.
No sweat. :)

> I have setup my application in order to use velocity within my jsp pages.
> For example I can easily use complex java objects defined as beans in,
> easily with velocity.
Good to hear that!

> I would like to go futher and use other very useful velocity component such
> as velocityTools; namely 
> VelocityView Tools , DateTools etc...
> 
> My questions:
> How should I set up my application in order to use these tools within my jsp
> page? I don't want to rename my '*.jsp' files into "*.vm".
> 
> In general what must I do in order to use velocity resources
> (ViewRenderTool, linkTool, MathToo, formTool, dateTool, velocityStruts and
> so on ... )within my Jsp page.
First, you must understand that tools are only POJOs in the Context. 
Nothing special. All you have to do, is create an instance and put it
in the Context, and you will be able to use it in the Velocity
template.

The VelocityViewServlet does this automatically using the toolbox
approach. You define the tools in toolbox.xml, and on each request,
it creates each tool and puts it in the ViewContext (the Context that
VelocityViewTool uses). Take a look at the VelocityTools source code
for more detail. ;)
http://jakarta.apache.org/velocity/tools/view/

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai 

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


		
---------------------------------
Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
Créez votre Yahoo! Mail

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis.Téléchargez GRATUITEMENT ici !

Re: Mixing JSP and velocity

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Chris,

> Thanks for your reply.
No sweat.  :)

> I have setup my application in order to use velocity within my jsp pages.
> For example I can easily use complex java objects defined as beans in,
> easily with velocity.
Good to hear that!

> I would like to go futher and use other very useful velocity component such
> as velocityTools; namely 
> VelocityView Tools , DateTools etc...
>  
> My questions:
> How should I set up my application in order to use these tools within my jsp
> page? I don't want to rename my '*.jsp' files into "*.vm".
>  
> In general what must I do in order to use velocity resources
> (ViewRenderTool, linkTool, MathToo, formTool, dateTool, velocityStruts and
> so on ... )within my Jsp page.
First, you must understand that tools are only POJOs in the Context. 
Nothing special.  All you have to do, is create an instance and put it
in the Context, and you will be able to use it in the Velocity
template.

The VelocityViewServlet does this automatically using the toolbox
approach.  You define the tools in toolbox.xml, and on each request,
it creates each tool and puts it in the ViewContext (the Context that
VelocityViewTool uses).  Take a look at the VelocityTools source code
for more detail.  ;)
    http://jakarta.apache.org/velocity/tools/view/

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


Re: Mixing JSP and velocity

Posted by "T. K. Chris" <ch...@yahoo.fr>.
Hi,
Thanks for your reply.
 
I have setup my application in order to use velocity within my jsp pages. For example I can easily use complex java objects defined as beans in, easily with velocity.
 
I would like to go futher and use other very useful velocity component such as velocityTools; namely VelocityView Tools , DateTools etc...
 
My questions:
How should I set up my application in order to use these tools within my jsp page? I don't want to rename my '*.jsp' files into "*.vm".
 
In general what must I do in order to use velocity resources (ViewRenderTool, linkTool, MathToo, formTool, dateTool, velocityStruts and so on ... )within my Jsp page.
 
Thanks
 
 

Shinobu Kawai <sh...@gmail.com> wrote:
Hi Chris,

> I have previously developed my web pages using JSP.
> After discovering velocity, I would like to migrate my pages into velocity.
> I can not envisage that since the number of pages is important.
> At this time, my page contains Struts and JSTL tags.
Very nice. Have a look through the VelocityTools documentation, too.
http://jakarta.apache.org/velocity/tools/

> My questions:
> 1- Is there possible to mix velocity and velocity in the same page?
Yeah, I think we all do that. Or are you talking about mixing
Velocity and JSP? B)
Anyways, it's possible. ;)

> 2- So How can I configure my application in order to use velocity within a JSP page.
Try here:
http://jakarta.apache.org/velocity/veltag.html
Looks like you have to build it, though.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai 

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


		
---------------------------------
Créez gratuitement votre Yahoo! Mail avec 100 Mo de stockage !
Créez votre Yahoo! Mail

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis.Téléchargez GRATUITEMENT ici !

Re: Mixing JSP and velocity

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Chris,

> I have previously developed my web pages using JSP.
> After discovering velocity, I would like to migrate my pages into velocity.
> I can not envisage that since the number of pages is important.
> At this time, my page contains Struts and JSTL tags.
Very nice.  Have a look through the VelocityTools documentation, too.
    http://jakarta.apache.org/velocity/tools/

> My questions:
> 1- Is there possible to mix velocity and velocity in the same page?
Yeah, I think we all do that.  Or are you talking about mixing
Velocity and JSP?  B)
Anyways, it's possible.  ;)

> 2- So How can I configure my application in order to use velocity within a JSP page.
Try here:
    http://jakarta.apache.org/velocity/veltag.html
Looks like you have to build it, though.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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