简体   繁体   English

命名(地图)构造函数在 grails.gsp.PageRenderer 中不起作用

[英]Named (map) constructors do not work in grails.gsp.PageRenderer

When I use a map constructor like:当我使用地图构造函数时:

Person p = new Person(name: "Bob")

through something that is called via a grails.gsp.PageRenderer, the field values are not populated.通过通过 grails.gsp.PageRenderer 调用的东西,不会填充字段值。 When I use an empty constructor and then set the fields individually like:当我使用空构造函数然后单独设置字段时:

Person p = new Person()
p.name = "Bob"

it succeeds.它成功了。 When I use the map constructor via a render call, it also succeeds.当我通过render调用使用地图构造函数时,它也成功了。

Any ideas as to why this is the case?关于为什么会这样的任何想法?

Sample project is here in case anyone wants to dig deeper: https://github.com/danduke/constructor-test/示例项目在这里,以防有人想深入挖掘: https : //github.com/danduke/constructor-test/

Actual use case, as requested by Jeff below:实际用例,如下 Jeff 所要求:

  • I have a computationally expensive view to render.我有一个计算成本很高的视图来渲染。 Essentially it's a multi-thousand page (when PDF'd) view of some data.本质上,它是一些数据的数千页(PDF 格式时)视图。
  • This view can be broken into smaller pieces, and I can reliably determine when each has changed.这个视图可以分解成更小的部分,我可以可靠地确定每个部分何时发生变化。
  • I render one piece at a time, submitting each piece to a fixed size thread pool to avoid overloading the system.我一次渲染一个片段,将每个片段提交到一个固定大小的线程池以避免系统过载。 I left this out of the example project, as it has no bearing on the results.我在示例项目中忽略了这一点,因为它与结果无关。
  • I cache the rendered results and evict them by key when data in that portion of the view has changed.当视图的该部分中的数据发生更改时,我缓存渲染的结果并通过键逐出它们。 This is why I am using a page renderer.这就是我使用页面渲染器的原因。
  • Each template used may make use of various tag libraries.使用的每个模板都可以使用各种标签库。
  • Some tag libraries need to load data from other applications in order to display things properly (actual use case: loading preferences from a shared repository for whether particular items are enabled in the view)一些标签库需要从其他应用程序加载数据才能正确显示内容(实际用例:从共享存储库加载首选项,以确定是否在视图中启用了特定项目)
  • When loaded, these items need to be turned into an object.加载时,这些项目需要变成一个对象。 In my case, it's a GORM object.就我而言,它是一个 GORM 对象。 This is why I am creating a new object at all.这就是为什么我要创建一个新对象。

There are quite a few opportunities for improvement in my actual use case, and I'm open to suggestions on that.在我的实际用例中有很多改进的机会,我愿意就此提出建议。 However, the simplest possible (for me) demonstration of the problem still does suggest that there's a problem.但是,最简单的(对我而言)问题的演示仍然表明存在问题。 I'm curious whether it should be possible to use map constructors in something called from a PageRenderer at all.我很好奇是否应该可以在从 PageRenderer 调用的东西中使用地图构造函数。 I'm surprised that it doesn't work, and it feels like a bug, but obviously a very precise and edge case one.我很惊讶它不起作用,感觉就像一个错误,但显然是一个非常精确和边缘情况的错误。

"Technically it is a bug" (which is the best kind of bug!), and has been reported here: https://github.com/grails/grails-core/issues/11870 “从技术上讲,这是一个错误”(这是最好的错误!),并已在此处报告: https : //github.com/grails/grails-core/issues/11870

I'll update this if/when additional information is available.如果/当有其他信息可用时,我会更新它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM