Search code examples
javagrailstags

GRAILS : <g:layoutTitle> does not work


I want to create layout for my grails application based on this tutorial: http://grails.asia/grails-tutorial-for-beginners-layout-templates

I create a page.gsp with the skeleton of my page:

<!DOCTYPE html>
<html>
<head>
    <title><g:layoutTitle default="Grails"/></title>
    <style>
    #header {background-color:#ffe0e0;text-align: center;}
    #footer {background-color:#e0e0ff;text-align: center;}
    </style>
    <g:layoutHead/>
</head>
<body>
    <div id="header">HEADER</div>

    <g:layoutBody/>
    <div id="footer">FOOTER</div>
</body>
</html>

And mainpage.gsp with main content:

    <!DOCTYPE html>
    <html>
    <head>
        <meta name="layout" content="page"/>
        <title>I am a test page</title>
        <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
    </head>
    <body>
    <p>Test page.</p>
    </body>
    </html>

Page is mapped in UrlMappings.groovy:

"/"(view:'/layouts/page')

But when I try to run my project I always got the error message like this:

URI/ Class java.lang.NullPointerException Message Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/layouts/page.gsp:4] Error executing tag : [views/layouts/page.gsp:4] Error executing tag : null Caused by null

Without it works properly. How can I solve this problem?


Solution

  • You should NOT display the decorator pages directly (out of grails-app/views/layouts dir). The purpose of those is to decorate OTHER pages.

    So, instead of the nonsense like

    "/"(view:'/layouts/page')
    

    you should be using smth like:

    "/"(view:'/mainpage')
    

    so that your mainpage.gsp is decorated by layouts/page.gsp.