velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Rotman <>
Subject Velocity alternative for WebMacro's Template.getParam?
Date Mon, 15 Nov 2004 08:32:46 GMT

I'm checking out the possibility to migrate some of our WebMacro
projects to Velocity. Now there's one thing that we use a lot in
WebMacro, for which I can't find a Velocity alternative just yet.

We use the Templage.getParam function from WebMacro to get some
parameters before
parsing the template.

Javadoc at:

Let me explain with a little example:

We have a WebMacro template (let's call it template.wm) looking like this:

#param $require = ["foo", "bar"]

Foo value is $foo
Bar value is $bar

Now when our servlet is instructed to return the template.wm Template,
the code looks somewhat like this:

public class FooServlet extends WMServlet {
    public Template handle(WebContext context) {
        Template template = getTemplate("template.wm");
        Object[] requiredParams = (Object[])template.getParam("require");
        for (int i = 0; i < requiredParams.length; i++)
            context.put(requiredParams[i], "-Value for "+requiredParams[i]+"-");
        return template;

This way the values for foo and bar are known when the template is displayed.

Is there a right way to do this in Velocity? The closest I came to
this using Velocity is creating a new VelocityContext, merge the
Template with this context, and get the value for require from that
context, but when doing this I get warnings in my log files about $foo
and $bar that are not yet set, so I really would like a "cleaner" way
to do this.

Thanks in advance,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message