velocity-user mailing list archives

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

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:
http://www.webmacro.org/api/org/webmacro/Template.html#getParam(java.lang.String)

Let me explain with a little example:

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

<html>
<body>
#param $require = ["foo", "bar"]

Foo value is $foo
Bar value is $bar
</body>
</html>

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,
Stefan.

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


Mime
View raw message