问题标签 [gsp]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
5688 浏览

grails - I can't get the grails controller "render" method to work with an explicit template

I'm just getting started with grails, and I'm having an issue.

I have a "controller" and "view" for the projects home page (there's no model for the home page)

I called the view "index.gsp", and put it in a directory views/home

However, no matter what I do, grails is trying to read the page "home.gsp" (and then home.jsp), despite me having explicitly specified the index with the "template" attribute in the render call.

I think I may be using the "template" attribute wrong, because I only see it used in examples for view-less template rendering. However the documentation gives no such limitation.

Is there any way to explicitly specify the name of a template? I just caved in and renamed it "home.gsp", but I'd like to understand what's going wrong.

(The home page in this application has no "model". Grails will use the controller has the model. In this example, you can access "someparameter" in the gsp template as ${someparameter}.)

0 投票
2 回答
7814 浏览

grails - 在 Grails 中格式化日期

我在 Grails 中有一个域类,其中包含一个字段 JourneyDate。JourneyDate 的定义如下:-

日期旅程日期

然后在我的 list.gsp 中显示如下日期:-

${fieldValue(bean:journeyInstance, 字段:'journeyDate')}

它以以下格式显示:-

2009-08-19 17:12:00.0

有谁知道我如何在 list.gsp 上对其进行格式化,使其不显示秒数?(我不想改变它在数据库中的存储方式)

0 投票
1 回答
1401 浏览

groovy - GSP 标签库导入

我正在尝试在 grails 之外使用 GSP 并遇到了我的第一个问题。

我似乎无法在我的 GSP 中进行 taglib 导入。

给定

当我运行我的应用程序时,

我得到一个

javax.servlet.ServletException:创建模板失败:groovy.lang.GroovyRuntimeException:无法解析模板脚本(您的模板可能包含错误或尝试使用当前不支持的表达式):启动失败:SimpleTemplateScript2.groovy:2:期待EOF,在第 2 行第 35 列找到“uri”。1 错误

有想法该怎么解决这个吗?

谢谢

0 投票
6 回答
13024 浏览

grails - 覆盖 grails.views.default.codec='html' 配置回 'none'

在 Grails (<2.3) 中,如果我留grails.views.default.code='none'在 grails Config.groovy 中,则由我在 GSP 文件中显式地对我的表达式进行 HTML 编码:${myValue?.encodeAsHTML()}.

如果我grails.views.default.codec='html"在 Config.groovy 中设置,那么 HTML 编码会自动为每个表达式发生:${myValue}.

我的问题:如果我将默认设置为,当我不想要 HTML 编码行为时'html',如何返回到一个表达式?'none'

0 投票
6 回答
10362 浏览

grails - 如何防止 Grails 缓存旧版本的 gsp 文件?

我正在修改 /grails-app/views/index.gsp。

当我保存文件并在 Firefox 中刷新http://localhost:8080/index.gsp时,我得到的是旧版本的文件。

有没有办法阻止 Grails 缓存和渲染文件的旧版本?

(我尝试重新启动服务器并清除 Firefox 的缓存。)

谢谢!

0 投票
1 回答
341 浏览

grails - Grails GSP 在 Geronimo 下不会生成预期的 HTML

在 Geronimo 2.1.4(jetty6、javaee5)下将我的 Grails 1.1-M2 应用程序作为 WAR 运行时,从 GSP 生成的 HTML 不包含我的动态内容。

具体来说,这个 GSP 片段:

...在 Geronimo 下运行时生成此 HTML:

...但是,当作为“grails run-app”或“grails run-war”运行时,会生成正确的 HTML:

AlbumType.groovy 在 src/groovy 中定义为:

我已经打开了 Grails 中的所有日志记录,没有看到任何错误或异常。这个问题令人困惑,因为我只在 Geronimo 下运行 Grails WAR 时看到它。诚然,我还没有尝试过任何其他应用程序服务器,但很好奇“grails run-app”和“grails run-war”一切正常。

关于这个问题的任何想法?

0 投票
4 回答
14115 浏览

grails - Grails“渲染”渲染模板

在我的 Grails 控制器中,我正在响应 AJAX 调用并render用于返回文本:

问题是render渲染整个模板。因此,它不仅呈现“姓名:约翰”,还呈现模板中定义的所有图标、导航等。如何在render没有模板的情况下进行渲染?

我非常关注使用 Grails 1.1.1 的“Grails in Action”(第 28 页)的第 1 章。

跟进:根据 Rhysyngsun 的建议返回 false 没有影响。我也尝试将模板设置为 null 但它仍然呈现模板:

render无论我做什么,它都会一心一意通过模板渲染它。

跟进 2:关于 grails-user 邮件列表的并行讨论。

跟进 3:示例代码:我将代码配对到最低限度,但它仍然表现出不希望的模板渲染。

控制器/PersonController.groovy:

views/person/home.gsp(查看主页方法的页面)

views/layouts/person.gsp(人员控制器的布局模板)

我使用主视图访问人员控制器: http://localhost:8080/test/person/home

页面呈现为:Test App ajax call (hyperlink) Message = Hello Blank

“测试应用程序”来自模板。当我单击“ajax 调用”时,它会异步调用 PersonController 的 ajaxTest 方法(使用 println 验证)。ajaxTest 所做的只是 println 并呈现静态文本。结果如下:

请注意,模板正在“test1”中呈现,<p>这会导致第二个“Test App”。

我正在运行 Grails 1.1.1。有任何想法吗?代码看起来很简单。我下载了 Grails 源代码并查看了 RenderDynamicMethod.java。除非模板在参数列表中,否则它不会进行任何模板渲染,但它不是。所以我唯一的猜测是再次渲染模板。

0 投票
1 回答
3221 浏览

java - 如何在 Grails 中配置和检索 ag:select 中的值?

我有 ag:select 在我的视图中显示产品列表:

${products} 是所有产品的列表。如果我打印传递给控制器​​的 params 变量,我会得到:

[产品:测试产品,库存:[id:1],inventory.id:1,操作:saveProductToInventory,控制器:库存]

产品密钥包含名称,而不是当我将 value="${it?.id}" 添加到 g:select 标记时我认为它会包含的 ID。

我如何需要声明 g:select 标记以呈现产品名称,但将产品的 id 作为值传递?

0 投票
5 回答
9022 浏览

grails - 如何在视图中调用 Grails 服务?

简单的问题:我有一个服务类(比如说helpersService)和一个方法def constructURI(params)。如何从模板视图调用此方法。

我尝试了以下代码但没有成功

但我得到以下结果:

或(如果我使用def helpersService

有任何想法吗?

0 投票
2 回答
5120 浏览

grails - Grails - 使用 gsp 每个测试集合中的第一个元素

有谁知道如何测试 gsp 循环中的第一个成员和最后一个成员?

这是我的jsp代码:

我知道您可以在 ag:each 语句中测试状态,但这只是一个整数。有什么东西可以访问第一个和最后一个元素吗?如果没有,还有其他方法可以做我正在做的事情吗?

任何帮助表示赞赏。