Grails
  1. Grails
  2. GRAILS-3818

Make rendering operations (views, templates etc.) possible on non request threads and from services and other beans

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.0.4, 1.1-beta2
    • Fix Version/s: 2.0-M1
    • Component/s: View technologies
    • Labels:
      None
    • Environment:
      Grails Application using asychronous jobs with GSPs

      Description

      The GroovyPagesTemplateEngine, which is responsible for rendering GSPs, isn't usable outside of a webrequest.
      Very common use-cases for rendering GSPs independently of a web-request are for example:

      • Sending HTML notification emails asynchronously (for example not possible with the MailPlugin at the moment)
      • A job that renders some static HTML files once the day

      Of course you can use Groovy's SimpleTemplateEngine for these use-cases.
      But you can't use custom tags and SiteMesh functionality which is a very big restriction compared to the GroovyPagesTemplateEngine.

        Issue Links

          Activity

          Hide
          Bob Tiernay added a comment -

          I agree this would be a very useful and popular feature as a quick search of nabble confirms.

          Currently, the easiest way to do this is described here:

          http://www.sinjax.net/wordpress/?p=1714

          Obviously this is clunky and could be made easier to support these contexts:
          1. request (http) / no-request (jobs, threads, async events)
          2. gsp file (from within app or file system) / gsp string (ie. from database, web service, user input)
          3. rendered from tag (inside a gsp <g:render string="$

          {s}

          ">) / rendered from controller (ex. render(string: s ...)

          As an aside, it appears as though GroovyPageWritable.writeTo ignores the passed in StringWriter (besides binding it to 'out' and later returning it). Perhaps this is a bug?

          Show
          Bob Tiernay added a comment - I agree this would be a very useful and popular feature as a quick search of nabble confirms. Currently, the easiest way to do this is described here: http://www.sinjax.net/wordpress/?p=1714 Obviously this is clunky and could be made easier to support these contexts: 1. request (http) / no-request (jobs, threads, async events) 2. gsp file (from within app or file system) / gsp string (ie. from database, web service, user input) 3. rendered from tag (inside a gsp <g:render string="$ {s} ">) / rendered from controller (ex. render(string: s ...) As an aside, it appears as though GroovyPageWritable.writeTo ignores the passed in StringWriter (besides binding it to 'out' and later returning it). Perhaps this is a bug?
          Hide
          Graeme Rocher added a comment -

          There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

          for 1.2 final only issues considered blocking will now be fixed

          Show
          Graeme Rocher added a comment - There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed
          Show
          Luke Daley added a comment - See http://jira.codehaus.org/browse/GRAILS-6809?focusedCommentId=250394&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_250394 on GRAILS-6809 for more discussion about this.
          Hide
          Graeme Rocher added a comment -

          There is a new PageRenderer bean that you can use to do this in Grails 2.0

          
          import grails.gsp.*
          class RenderTestService {
          	
          	PageRenderer groovyPageRenderer
          
              def testRenderTemplate() {
          		groovyPageRenderer.render template:"/foo/bar"
              }
          }
          

          There are some limitations as to what you can do since there is no request. And all links to others templates, controllers etc. have to be fully qualified.

          Show
          Graeme Rocher added a comment - There is a new PageRenderer bean that you can use to do this in Grails 2.0 import grails.gsp.* class RenderTestService { PageRenderer groovyPageRenderer def testRenderTemplate() { groovyPageRenderer.render template: "/foo/bar" } } There are some limitations as to what you can do since there is no request. And all links to others templates, controllers etc. have to be fully qualified.

            People

            • Assignee:
              Graeme Rocher
              Reporter:
              Mos
            • Votes:
              15 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development