I want to add namespaces in my struts2 configuration and I use tiles.
A package of my struts.xml for example :
<package name="search" namespace="/search" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="SearchActionInit" class="web.action.SearchAction" method="initSearch">
<result name="input" type="tiles">search</result>
<result name="success" type="tiles">search</result>
</action>
</package>
And the corresponding tiles configuration :
<definition name="baseLayout" template="layout.jsp">
<put-attribute name="titre" value="titre.default" />
<put-attribute name="header" value="/common/header.jsp" />
<put-attribute name="menu" value="/common/menu.jsp" />
<put-attribute name="leftcontent" value="/common/leftcontent.jsp" />
<put-attribute name="rightcontent" value="/common/rightcontent.jsp" />
<put-attribute name="detail" value="/common/detail.jsp" />
<put-attribute name="footer" value="/common/footer.jsp" />
</definition>
<definition name="search" extends="baseLayout">
<put-attribute name="titre" value="titre.search" />
<put-attribute name="rightcontent" value="/pages/search/Search.jsp" />
</definition>
The problem I have is that I need to duplicate the layout.jsp in a search folder for the namespace search (and so on for the other namespaces). It's not in the tiles logic and will bring more effort to maintain.
Has anybody a key to this problem to avoid duplication?
try this:
template:
then the data:
You need only overwrite the part of the page
layout.jsp
, which you'd like to load.here is my project structure:
I hope this solves your problem.