Announcement Announcement Module
No announcement yet.
Difficulties using Grails PageRenderer in service Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difficulties using Grails PageRenderer in service

    I created a simple integration test for a service using a template. Basically, pass some kind of model to the GSP and render it, with the test comparing against a simple string. Sounds easy. All the examples of this usage seem to be consistent, but I get an NPE when I execute it. Many of the examples on the web used no constructor, but since that obviously won't work on the third line of code, I did a new on it, and tried to add a GroovyPagesTemplateEngine as well, in the end.

    Here's the service code:
    def listApprovals(userSso) {
    		PageRenderer groovyPageRenderer = new PageRenderer()
    		def results // no need for the code here, just passing a null for now
    		groovyPageRenderer.render template: '/policy/approval', model: [approvals: results]
    And here's the silly simple template:
    // _approval.gsp
    Here are your approvals ${approvals}
    I get a null pointer exception as follows: In the PageRenderer class, there is an expectation set:
    private void renderViewToWriter(Map args, Writer writer) {
            def source = null
            if (args.view) {
               source = groovyPageLocator.findViewByPath(args.view.toString())
            else if (args.template) {
                source = groovyPageLocator.findTemplateByPath(args.template.toString())
    the variable groovyPageLocator is null, so it's obvious that I'm constructing that PageRenderer class wrongly. or the groovyPageLocator does not get properly injected when the service is initialized.

    I need your thoughts.