Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-33675

Include the HttpServletResponse in the velocity context of velocity templates

    Details

      Description

      In the method VelocityVariablesImpl.java#insertVariables(VelocityContext, HttpServletRequest) the HttpServletRequest is added to the velocityContext:

      VelocityVariablesImpl.java
      public void insertVariables(VelocityContext velocityContext, HttpServletRequest request) throws Exception {
          // Request
          velocityContext.put("request", request);
      ...
      

      Please also add the HttpServletResponse to the same velocityContext. Use cases:

      1. from a velocity template (i.e. .tpl or .vm file) we would be able to force some response headers
      2. only with a response object we can perform redirect and forward
      3. many other use cases if we have access to the methods of a response object

      The current workaround is to create a ServicePreAction hook (i.e. servlet.service.events.pre) and add the response object to the request as an attribute:

      MyServicePreAction.java
      ...
      public void run(final HttpServletRequest request, final HttpServletResponse response) {
          request.setAttribute("response", response);
      }
      ...
      

        Attachments

          Activity

            People

            • Assignee:
              support-lep@liferay.com SE Support
              Reporter:
              remis Remis Baima
            • Votes:
              2 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: