Results 1 to 2 of 2

Thread: Exposing velocity context

  1. #1
    Join Date
    Oct 2004
    Posts
    4

    Default 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. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    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.
    Darren Davison.
    Public Key: 0xE855B3EA

Similar Threads

  1. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. FreeMarker vs Velocity
    By Martin Kersten in forum Architecture
    Replies: 8
    Last Post: May 30th, 2005, 09:21 AM
  4. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  5. GET parameters and Velocity context
    By brianstclair in forum Web
    Replies: 2
    Last Post: Sep 25th, 2004, 10:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •