Announcement Announcement Module
Collapse
No announcement yet.
Exposing velocity context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exposing velocity context

    I am very happy with Springs out of the box support for alternative view technologies like Velocity and FreeMarker.

    We are using velocity for a part of our project. We have been trying to add a tool to our velocity pages, specifically the render tool. We are passing the tool through a request attribute. The problem is, this tool requires the velocity context in the page. We are quite lost on how we can do that. How can we access the velocity context from a velocity page?

    Thanks in advance.

  • #2
    I think the simplest way to get what you want is to extend VelocityView and override the mergeTemplate method as follows (UNTESTED);
    Code:
    protected void mergeTemplate(Template template, Context context, HttpServletResponse response)
      throws Exception {
      // add self reference to the context
      context.put("velocityContext", context);
      template.merge(context, response.getWriter());
    }
    Then your render tool can access the context itself with the name "velocityContext".

    Let us know how you get on.

    Comment

    Working...
    X