gpt4 book ai didi

grails - Grails资源-无法在布局中添加r.script?

转载 作者:行者123 更新时间:2023-12-02 14:20:19 26 4
gpt4 key购买 nike

我制作了一个脚本,该脚本根据当前请求的语言环境加载内容。就像是

class ScriptsTagLib {
static namespace = "my"
def loadLangInfo = { attrs ->
Locale locale = RequestContextUtils.getLocale(request)
r.script() {
out << '$(function(){ loadLangInfo("'+locale.language+'") });'
}
}
}

如果将其添加到布局中,页面将引发错误:

Error evaluating expression [my.loadLangInfo()] on line [6]: Cannot add module [-page-fragments-] which requires disposition [defer] to this request - that disposition has already been rendered.

Error 2012-11-19 15:13:54,801 [http-bio-8080-exec-5] ERROR [Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=500, location=/grails-errorhandler] Message: java.io.UnsupportedEncodingException: The character encoding [null] is not supported



但是,如果我在页面中而不是布局中添加此标记,则页面将成功呈现。

无法在布局中添加 r.script()吗?

编辑:问题实际上是布局中的资源。另一个失败的示例是:
<g:layoutHead/>
<r:script>
$(function(){ });
</r:script>
<r:layoutResources />

编辑2:有关上下文的更多信息
  • Grails 2.0.4
  • 资源1.2.RC2

  • 另外,它是插件内部的布局,而不是一个应用程序。

    尚未在Grails 2.1中进行测试,但可以这样做。

    编辑3 :

    现在刚刚测试,使用 Grails 2.1.1Grails 2.0.4新的新 插件项目,布局中的script标签将被忽略!

    ./views/layout/test.gsp->脚本被忽略
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><g:layoutTitle default="Insoft4 UI Plugin"/></title>
    <g:layoutHead/>

    <r:layoutResources />
    </head>
    <body>
    <g:layoutBody/>
    <r:script disposition="defer">
    alert('layout!');
    </r:script>
    <r:layoutResources />
    </body>
    </html>

    ./views/index.gsp->脚本确定
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Teste</title>
    <meta name="layout" content="teste" />
    <r:script disposition="defer">
    alert('index!');
    </r:script>
    <r:layoutResources />
    </head>
    <body>
    <h1>Testing this index!</h1>
    <r:layoutResources />
    </body>
    </html>

    最佳答案

    我发现当您在布局和页面中都声明了<r:layoutResources />并尝试在布局中添加脚本时,便会出现问题。

    为了更正,我从每个 View 中删除了layoutResources,仅保留在布局中。

    关于grails - Grails资源-无法在布局中添加r.script?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13460733/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com