velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Why cant I pass "arrays" to object methods?
Date Sat, 10 Feb 2001 15:27:50 GMT
mike@bodaro.com wrote:
> 
> Thanks, I tried it and it now works well. Very cool, even does method
> overloading.
> 
> Next question ( a bit harder):
> 
> I would like to parse the web page (*.vm) myself, sending Velocity
> portions of the template page a bit at a time.
> 
> Another way to look at is to send Velocity a portion of the page (a
> snippit of the template) have it process, then my servlet does some other
> stuff, send Velocity more VTL code, do some more stuff,...

Ok.  But out of sheer curiosity, what's the point?

If you are trying to make a 'dynamic' template of sorts, where you
construct the final output from pieces, there are several features of
Velocity and VTL that help in doing this, while maintaining the
convenience of a template that's easy to maintain, edit and extend.

1) #parse( arg ) : will take the arg, parse and render it against the
current context, and insert that stream into the output stream.
2) #include( arg ) : will take the arg and insert as is into the stream.
(no parseing or rendering)
3) Velocimacros : go see the docs :)

This may not be what you want to do though.. I am just guessing.

> Is there a way to stream text to Velocity rather than passing a filename?
> Could I easily? Implment this as an alternative method call in
> VelocityServlet?

Yes, there is a way to be more 'granular' about processing.  There is a
class called Velocity that is currently in the whiteboard/geir
directory, and will be checked into CVS this morning as
org.apache.velocity.util.Velocity.

This class has two static methods 
 
 public static  boolean evaluate( Context context,  Writer out, String
logTag, String instring )
 public static boolean evaluate( Context context, Writer writer, String
logTag, InputStream instream )
 
that allow you to parse and process an InputStream or String into a
Writer, just like a template would be.  I think this is what you are
asking for.

You would have to make your own servlet, but it is really easy.  Just
make sure you init() the Velocity engine correctly - see how
VelocityServlet does it.

As I don't know what you are doing, or what your experience level is, I
will spare you the preaching about MVC/Model2 architecture, and what
Velocity does to help support this design pattern.  But if you are
unfamiliar with this, I would give it a look-see :

http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html

geir


-- 
Geir Magnusson Jr.                               geirm@optonline.com
Velocity : it's not just a good idea. It should be the law.
http://jakarta.apache.org/velocity

Mime
View raw message