Struts2 中的tiles.xml 中是否可以有动态值 [英] Is it possible to have dynamic values in tiles.xml in Struts2

查看:26
本文介绍了Struts2 中的tiles.xml 中是否可以有动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像在 Struts2 中的 struts.xml 中那样在tiles.xml 中传递动态值?我已经使用 ${parameter} 在配置文件中获取动态值,但它似乎不起作用.有任何想法吗?

Is it possible to pass dynamic values in tiles.xml as we do in struts.xml in Struts2? I have used ${parameter} to get dynamic values in config file but it doesnt seem to work. Any ideas?

推荐答案

你可以将通配符从你的 struts 动作传递给磁贴,我已经用它为动态项目做类似的事情,其中​​每个客户端可能有不同的 CSS 文件实例.

You can pass wildcards to tiles from your struts actions, I've used this to do similar things for dynamic projects where each client might have a different CSS file for instance.

在您的 struts 操作中,您将拥有一个图块结果类型,您可以传递如下值:

In your struts action you would have a tiles result type and you can pass the value such as:

<action name="{eventURL}/update" class="org.groundworkgroup.struts.actions.admin.UpdateEventSettings">
    <result name="login" type="tiles">/login.tiles</result>
    <result name="input" type="tiles">/admin.${#session.bean.pageID}.${#session.bean.fileID}.tiles</result>
    <result name="success" type="tiles">/admin.${#session.bean.pageID}.${#session.bean.fileID}.tiles</result>
</action>

然后在你的tiles.xml中你会插入"通配符:

And then in your tiles.xml you would "plug in" the wildcards:

<definition name="/admin.*.*.tiles" extends="adminLayout">
    <put-attribute name="title" value="Welcome" />
    <put-attribute name="jsfile" value="{1}/js/{2}.js" />
    <put-attribute name="cssfile" value="{1}/css/{2}.css" />
    <put-attribute name="body" value="/WEB-INF/content/sites/admin/main.jsp" />
    <put-attribute name="menu" value="/WEB-INF/content/sites/admin/menu.jsp" />
</definition>

在这个特定的例子中,struts action pageID 是文件所在的项目目录,在tiles.xml 中它被放置为通配符{1}.fileID 是与此特定操作或用户关联的文件名,在tiles.xml 中由{2} 表示.您可以使用此设置将动态值传递给您的磁贴,以控制例如页面状态或 JSP 的呈现或在此示例中的自定义 css 和 js 文件.

In this particular example the struts action pageID is the project directory where the files are located and in the tiles.xml it is placed as wildcard {1}. The fileID is the filename associated with this particular action or user represented in the tiles.xml by {2}. You can use this set up to pass dynamic values to your tiles in order to control for example page states or JSP's to render or like in this example, custom css and js files.

这篇关于Struts2 中的tiles.xml 中是否可以有动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆