Announcement Announcement Module
Collapse
No announcement yet.
$req with Velocity Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • $req with Velocity

    Hi folks,

    We're using Velocity for templating with Spring MVC.

    I've seen elsewhere references to a $req model property being available - any attempt to use it doesn't work, with "$req.xxxx" being rendered in HTML.

    Further digging suggests that the VeloctyViewResolver has a "setExposeRequestAttributes" method (according to the api documentation). Setting this property via the spring configuration of the ViewResolver seems to have no effect.

    No matter what we've tried, we can't get "automatic" access to the Servlet request - adding it manually to the model works, but is less than convenient.

    Cheers,
    Damian.

  • #2
    if you expose request attributes via the method highlighted, the attributes are simply added to the model as first class citizens, so there's no $req prefix or anything else.

    Another available option via the view resolver or individual Velocity views is to expose a RequestContext object by setting the setRequestContextAttribute() to the name you wish to access it under. Commonly "rc" to make it available in your templates as $rc. See http://www.springframework.org/docs/...stContext.html for details of what this gives you access to in the template.

    Regards,

    Comment


    • #3
      Originally posted by davison
      Another available option via the view resolver or individual Velocity views is to expose a RequestContext object by setting the setRequestContextAttribute() to the name you wish to access it under. Commonly "rc" to make it available in your templates as $rc.
      Brilliant - I was after the request context, so was exactly what I needed - thanks!

      Comment

      Working...
      X