You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by bart wood <ba...@hotmail.com> on 2003/06/05 20:48:31 UTC

Veltag with struts tools

Hi,
I want to use velocity in my struts application.  I need the ability to 
re-use a lot of existing jsp/struts tags but mix in velocity markup.  The 
Veltag tag library seemed very promising to allow me to do this.  However, I 
found that mixing the VelocityTag code with the VelocityViewServlet code is 
not possible.  I downloaded the source of both and peeked around to figure 
out how to mix the two.  I tried this piece of code in VelocityTag.doEndTag( 
)

RequestDispatcher rd = pageContext.getServletContext().getNamedDispatcher( 
"/velocity" );
rd.include( pageContext.getRequest( ), pageContext.getResponse( ) );

The VelocityViewServlet.doRequest method is called but it crashes.  Probably 
because the VelocityViewServlet is expecting a file to parse instead of the 
tag body.  I thought of creating a temporary file but that is really messy.  
Does anyone have any code that does this same thing or something similar.  
How can I combine the Veltag functionality with the velocity tools package?

Thanks

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


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


Oops! (Was: Veltag with struts tools)

Posted by Jonathan Revusky <jo...@revusky.com>.
Honestly, I meant to send this message by private email, but I forgot to 
change the recipient before hitting the send button.

I'm not very interested in starting a fight with anyone here. I don't 
have the time or energy to get abused by anybody. My sending this to the 
list really was unintentional.

Jonathan

Jonathan Revusky wrote:
> bart wood wrote:
> 
>> Hi,
>> I want to use velocity in my struts application.  I need the ability 
>> to re-use a lot of existing jsp/struts tags but mix in velocity 
>> markup.  The Veltag tag library seemed very promising to allow me to 
>> do this.  However, I found that mixing the VelocityTag code with the 
>> VelocityViewServlet code is not possible.  I downloaded the source of 
>> both and peeked around to figure out how to mix the two.  I tried this 
>> piece of code in VelocityTag.doEndTag( )
> 
> 
> Bart,
> 
> If you are interested in using Struts sans JSP, you might consider 
> FreeMarker for your view layer. FreeMarker is an open-source template 
> engine, much like Velocity, but generally more powerful and is also 
> undergoing more active development.
> 
> FreeMarker integrates quite well with struts, but also you get to have 
> your cake and eat it too, since FM now supports the use of 3rd party JSP 
> taglibs from templates, so if there is some functionality in a taglib 
> that you need, you can still use it. Velocity doesn't have this feature 
> and, truth told, probably never will. You see, Velocity is basically a 
> dead project. No new development on the template engine itself has 
> occurred for about a year.
> 
> Here is the manual section that says how to use FM in conjunction with 
> Struts and with JSP taglibs in general:
> 
> http://freemarker.org/docs/pgui_misc_servlet.html
> 
> FreeMarker is also used as the view component in various web application 
> frameworks. Notably, "Open for Business", http://ofbiz.org recently 
> decided to move over completely from using JSP to using FM.
> 
> I hope that's helpful.
> 
> Jonathan Revusky



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


Re: Veltag with struts tools

Posted by Jonathan Revusky <jo...@revusky.com>.
bart wood wrote:
> Hi,
> I want to use velocity in my struts application.  I need the ability to 
> re-use a lot of existing jsp/struts tags but mix in velocity markup.  
> The Veltag tag library seemed very promising to allow me to do this.  
> However, I found that mixing the VelocityTag code with the 
> VelocityViewServlet code is not possible.  I downloaded the source of 
> both and peeked around to figure out how to mix the two.  I tried this 
> piece of code in VelocityTag.doEndTag( )

Bart,

If you are interested in using Struts sans JSP, you might consider 
FreeMarker for your view layer. FreeMarker is an open-source template 
engine, much like Velocity, but generally more powerful and is also 
undergoing more active development.

FreeMarker integrates quite well with struts, but also you get to have 
your cake and eat it too, since FM now supports the use of 3rd party JSP 
taglibs from templates, so if there is some functionality in a taglib 
that you need, you can still use it. Velocity doesn't have this feature 
and, truth told, probably never will. You see, Velocity is basically a 
dead project. No new development on the template engine itself has 
occurred for about a year.

Here is the manual section that says how to use FM in conjunction with 
Struts and with JSP taglibs in general:

http://freemarker.org/docs/pgui_misc_servlet.html

FreeMarker is also used as the view component in various web application 
frameworks. Notably, "Open for Business", http://ofbiz.org recently 
decided to move over completely from using JSP to using FM.

I hope that's helpful.

Jonathan Revusky
-- 
lead developer FreeMarker project, http://freemarker.org


> 
> RequestDispatcher rd = 
> pageContext.getServletContext().getNamedDispatcher( "/velocity" );
> rd.include( pageContext.getRequest( ), pageContext.getResponse( ) );
> 
> The VelocityViewServlet.doRequest method is called but it crashes.  
> Probably because the VelocityViewServlet is expecting a file to parse 
> instead of the tag body.  I thought of creating a temporary file but 
> that is really messy.  Does anyone have any code that does this same 
> thing or something similar.  How can I combine the Veltag functionality 
> with the velocity tools package?
> 
> Thanks
> 
> _________________________________________________________________
> The new MSN 8: advanced junk mail protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail



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


RE: Veltag with struts tools

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

I'm sure Nathan will chime in, but I think this will be going against
the grain.

Veltag is a way to inject bits of VelocityTemplate into a JSP page. The
tag instantiates a velocity engine and 'borrows' the request/session/app
attributes
to use as a VelocityContext. 

VelocityView and StrutsTools aim to use VelocityTemplates directly with
Struts - no JSP involved. The Velocity view knows how to render *.vm
files and the Struts Tools provide the glue to make the Struts objects
available.

Take a gander at this pretty diagram:
http://www.happysearch.com/velocity/tools/docs/struts/

I think it sounds like what you want is to have a VelocityTemplate that
understands JSP Taglibs.

Ex. foo.vm
------
Howdy I am a $Velocity template
<bart:table_tag table="USERTABLE">
  <TD><%=DATA%></TD>
</bar:table_tag>
-------

I predict the probability of this being coded at <0.00000001, or less.
;-)

For this to work, the Velocity engine would have to understand that the
bart:table_tag was a JSP tag and then somehow use JASPER.JAR to process
it.

My two cents - Keep the JSPs for now and slowly migrate to *.vm files
where it makes sense.

Both can be used in the same application simultaneously, just change the
Struts forward mapping from foo.jsp to foo.vm.

I have often found that the Custom Tag functionality can be done easier
using Velocity Macros, but of course your mileage may vary. :-)

Cheers Timo


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