Apache Tiles:在运行时更改模板页面
我有一个问题:假设在 Spring MVC 3.0 环境中我使用 Tiles 管理视图:我有一个包含所有视图定义的 xml 文件。每个视图都扩展一个特定的模板。我有两个模板:一个用于渲染completeDOM(),一个用于partialDOM(.....)。问题是,有一些视图可以在fullDOM和partialDOM中检索,但我不想写出两个相似的定义。
我正在考虑一种动态方法:在运行时注入视图的模板,指定一个应包含模板名称的 http 参数。如果请求包含该参数,则 Tiles 应该使用 http 参数值检测到的模板来覆盖视图扩展的模板。
一些建议?
I have a question : suppose that in a spring MVC 3.0 enviroment i manage Views with Tiles : I have a xml file with definitions of all views. Every view extends a specific template. I have two templates : one for rendering a completeDOM () and one for partialDOM (.....).The problem is, there are some views that can be retrieved in fullDOM and also in partialDOM, but i don't want to write two similars definitions.
I was thinking to a dynamic approach : inject the template of a view at runtime, specifying an http parameter which should contains the name of the template. If the request contains the parameter, than Tiles should override the template exteded by the view, with the template detected by http parameter value.
Some suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这是一个老问题,但我需要做这件事,所以我想我会分享我的解决方案。
Tiles 允许他们所谓的“运行时组合”,它可以让您修改定义。因此,您可以重用现有定义并只需交换模板:
I know this is an old question but I had needed to do this very thing so I thought I'd share my solution.
Tiles allows what they refer to as "runtime composition", which lets you modify definitions. So you can reuse an existing definition and just swap the template:
在 springtilesConfigurer 中,您需要设置可变容器:
在 Spring 控制器中:
In spring tilesConfigurer you need to set mutable container:
And in your Spring Controller:
我认为视图准备器可能会有所帮助:
http://tiles.apache.org/framework/tutorial/advanced/preparer.html
I think a view preparer might help:
http://tiles.apache.org/framework/tutorial/advanced/preparer.html