1

Recently began using Jtwig and have no idea how to easily obtain session, servletrequest, remote user and so on. In Thymeleaf, for example, it can be done that way:

<span th:text="${#httpServletRequest.remoteUser}"></span>
...
<p th:text="${#httpSession.getValue(...)}"></p>

Documentation nor Google was not able to answer my question. Probably, this is not implemented (yet?) and i always must put necessary objects manually into the ModelMap?

VirtualVoid
  • 1,005
  • 3
  • 17
  • 25

1 Answers1

1

The request object is added to the model for free. For example, to access the remote user:

{{ request.remoteUser }}

To access a session attribute:

{{ request.session.getAttribute('user') }}

Basically, follow the servlet API starting with the request variable.

João Melo
  • 726
  • 7
  • 8
  • Thanks, very appreciated! But i wonder, why isn't this mentioned in documentation? And is there something else that being added to the Model? (I've tried to set some breakpoints and had no luck to catch something). – VirtualVoid Oct 28 '14 at 00:14
  • A-ha. Seems i figured it out myself. There are beans, theme and request. JtwigView.renderMergedTemplateModel. – VirtualVoid Oct 28 '14 at 01:51