我想根据本教程为我的 grails 应用程序创建布局: http://grails.asia/grails-tutorial-for-beginners-layout-templates
我使用页面的骨架创建了一个 page.gsp:
<!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>
mainpage.gsp 的主要内容:
<!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>
页面在 UrlMappings.groovy 中映射:
"/"(view:'/layouts/page')
但是当我尝试运行我的项目时,我总是收到如下错误消息:
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
没有它就可以正常工作。 我该如何解决这个问题?
最佳答案
您不应该直接显示装饰器页面(在 grails-app/views/layouts
目录之外)。这些的目的是装饰其他页面。
所以,不要像这样废话
"/"(view:'/layouts/page')
你应该使用类似的东西:
"/"(view:'/mainpage')
这样你的mainpage.gsp
就被layouts/page.gsp
装饰了。
关于java - chalice : <g:layoutTitle> does not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50164047/