开发者

Is it possible to have dynamic values in tiles.xml in Struts2

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?


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.

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>

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>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜