Ones Self said: ... > What I need is a new directive (I'll call it #parses), which parses a > string instead of a file. So for example: > > #set( $var = "hello" ) > #parses( "$var" ) ...
you can use the RenderTool (http://jakarta.apache.org/velocity/tools/generic/) or ViewRenderTool (http://jakarta.apache.org/velocity/tools/view/) > The basic idea behind my project is that the vast majority of Velocity > driven HTML pages have the same basic structure. this is one reason people often use Velocity (and VelocityTools) with web frameworks like Maverick, Struts, WebWork, or Turbine. if you're looking for a lighterweight solution, the combination of VelocityTools and Velosurf (http://www.sf.net/projects/velosurf) seems quick and easy for small/simple webapps. ... > We have a Java class that loads a > template, preforms database operations based on an earlier submit or > parameters, and then loads new data for the Context object. I thought > it would be a good idea to incapsulate this structure into an API. sounds like it would be a new mini-framework of sorts. > The basic structure of my API is as follows: It contains a > TemplateServlet, which extends VelocityServlet, and overwrites the > handleRequest method. FYI: the VelocityServlet has recently been deprecated in favor of the VelocityViewServlet in the VelocityTools project. ... > The problem with this is that there's no way to pass a reference to a > Velocity macro to another Velocity macro. I could also pass the > string name of the macro, but there's no way to parse a string as VTL > code, is there? the rendering tools mentioned above are the canonical hack nowadays, though i should warn you that they presently don't work with the setting: velocimacro.permissions.allow.inline.local.scope=true (http://issues.apache.org/bugzilla/show_bug.cgi?id=25834) > A good solution might be to have #parse directive > (possibly with a different name like #parses, for parse string) that > would parse a string. a better name would be #render, and this isn't a bad idea. i doubt it would ever be accepted into the core of VTL, but i think it would be nice to have one of these in the contrib directory or some sort of optional package. > Another use for the #parses directive, would be > to be use as link templates. So you could do something like this: > > #set( person_id = "jane" ) > #* $someTemplate might be "Person?person_id=$person_id" set in Java *# > <a herf="#parses( $someTemplate )">link</a> i don't think i understand this, but it doesn't look good to me. for building URIs, you should look at the LinkTool (in VelocityTools). > This code obviously needs more time to mature before it's really > useful. depends on what you mean by "really useful", it sounds like it's already fairly useful to you. :) > The full code is available at > <http://www.generationr.net/eyal/example.tar.gz> > http://www.generationr.net/eyal/example.tar.gz. > I would love to hear your thought about this. Do I have something > interesting here? Are there ten other projects out there already doing > the same thing? Is my idea useless? Any comments would be greatly > appreciated. yeah, there are plenty of webapp frameworks out there and several work very well with Velocity, but this does look like a somewhat unique approach (in my experience). given that, it piques my curiousity, but i admit i don't have much time to look into it and probably won't since i'm already invested in other frameworks. Nathan Bubna [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
