我继承了一个使用Struts 1.2 Tiles 1的旧应用程序。出于各种令人烦恼的原因,我无法升级。
我对Struts不太熟悉,或者特别是Tiles,我正在尝试做一些在我脑海中有意义的事情,但我似乎无法在实践中完成工作。这是我想要完成的一个例子:
<tiles-definition>
<definition name="content-with-sidebar" path="/content_with_sidebar.jsp">
<put name="top" value="" type="string" />
<put name="sidebar" value="/tiles/sidebar.jsp" />
<put name="main" value="" type="string" />
<put name="bottom" value="" type="string" />
</definition
</tiles-definition>
content_with_sidebar.jsp
...
<tiles:insert attribute="top" flush="false" />
<div id="content">
<aside>
<tiles:insert attribute="sidebar" flush="false" />
</aside>
<div id="main">
<tiles:insert attribute="main" flush="false" />
</diV>
</div>
<tiles:insert attribute="top" flush="false" />
...
actual_page.jsp
<tiles:insert definition="content-with-sidebar" flush="false">
<tiles:put name="top" type="string">
<div>Maybe this page has something on the top that isn't the page header</div>
</tiles:put>
<!-- use the default sidebar -->
<tiles:put name="main">
<strong>Current Location:</strong>
<address><h:outputText value="#{locationDesc} #{zipCode}" /></address>
<!-- Some more dynamic jsp markup -->
</tiles:put>
<!-- This one doesn't have anything extra on the bottom -->
</tiles:insert>
这几乎可以工作,但动态位在<tiles:insert>
之上和之外呈现,而普通字符串就在它们应该的位置。经过多次搜索,我现在明白了,<tiles:put>
在这个呃上下文中,期待一个简单的字符串。
是否有一种模式可以通过动态上下文实现我想要的效果?
目前我不得不创建另一个由<tiles:put>
标记引用的jsp文件。即。
<tiles:put name="main" value="/actual_page_body.jsp" />
我宁愿不必创建一个额外的文件。任何建议都会有所帮助。
答案 0 :(得分:0)
使用图块,当呈现定义时(代码中带有侧边栏的内容),jsp对应于&#39;路径&#39;将调用attribute(/content_with_sidebar.jsp)。必须使用<tiles:insert>
手动调用所有其他jsps。 tile提供的是一种以配置方式将它们作为定义属性调用的方法。