我在Grails应用程序的“主”布局文件中设置了一些GSP变量(包括下面的内容)。这些变量的值在sitemesh呈现的GSP页面中似乎不可访问。此外,它们在标记呈现的任何模板中都不可见。我尝试过在下面设置scope=“请求”(请参阅代码),但这似乎没有任何区别。我显然不理解GSP变量的范围规则。
有谁能澄清GSP变量的作用域,并建议我如何从布局到模板(如果可以的话)来传递它们。
<!DOCTYPE html>
<%-- <html lang="${org.springframework.web.servlet.support.RequestContextUtils.getLocale(request).toString().replace('_', '-')}"> --%>
<html lang="${session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'}">
<head>
<title><g:layoutTitle default="${meta(name:'app.name')}" /></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<asset:javascript src="bootstrap.js" />
<theme:load />
<asset:javascript src="application.js" />
<asset:stylesheet src="application.css" />
<asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<g:layoutHead />
<%-- Defineform body layout column dimensions. These values are used by Bootstrap based forms to
layout using configured column widths and offsets. --%>
<g:set var="labelWidth" value="${grailsApplication.config.ark.layout.labelWidth ?: 'col-sm-3'}" scope="request" />
<g:set var="controlWidth" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-4'}" scope="request" />
<g:set var="controlOffset" value="${grailsApplication.config.ark.layout.controlWidth ?: 'col-sm-offset-3'}" scope="request" />
<%-- For Javascript see end of body --%>
</head>
<body>
<g:render plugin="arkUi" template="/layouts/menu/navbar"/>
<g:render plugin="arkUi" template="/layouts/content"/>
<g:render plugin="arkUi" template="/layouts/footer"/>
<!-- Include deferred Javascript files and other resources -->
<asset:deferredScripts/>
</body>
</html>发布于 2014-12-08 19:54:40
这里的问题是Grails首先解析目标GSP页面以确定要使用的布局,然后解析布局GSP并组合它们。因此,布局可以看到您在页面中设置的变量,但反之亦然。
https://stackoverflow.com/questions/27363113
复制相似问题