Found some very good examples online that integrate Struts 2 with Tiles 2. I noticed that ALL of them map actions using wildcard method from a single action class. Is there a reason for doing so? My application doesn't work when I map actions individually to multiple classes. In the code below, lookUpAll
action was added by me. Rest of the code is from the example I am trying to follow.
Struts.xml:
<struts>
<package name="default" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="*Link" method="{1}" class="action.LinkAction">
<result name="welcome" type="tiles">welcome</result>
<result name="friends" type="tiles">view</result>
<result name="office" type="tiles">office</result>
</action>
<action name="lookUpAll" class="action.LookupAll">
<result name="success" type="tiles">view</result>
<result name="error" type="tiles">lookFail</result>
</action>
</package>
</struts>
Tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="title" value="Template"/>
<put-attribute name="header" value="/header.jsp"/>
<put-attribute name="menu" value="/menu.jsp"/>
<put-attribute name="body" value="/body.jsp"/>
<put-attribute name="footer" value="/footer.jsp"/>
</definition>
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="Welcome"/>
<put-attribute name="body" value="/welcome.jsp"/>
</definition>
<definition name="view" extends="baseLayout">
<put-attribute name="title" value="View"/>
<put-attribute name="body" value="/DispSchedule.jsp"/>
</definition>
<definition name="lookFail" extends="baseLayout">
<put-attribute name="title" value="LookFail"/>
<put-attribute name="body" value="/lookUpFail.jsp"/>
</definition>
<definition name="friends" extends="baseLayout">
<put-attribute name="title" value="Friends"/>
<put-attribute name="body" value="/friends.jsp"/>
</definition>
<definition name="office" extends="baseLayout">
<put-attribute name="title" value="Office"/>
<put-attribute name="body" value="/office.jsp"/>
</definition>
</tiles-definitions>
Using a wildcard is not required, but is convenient when the app uses Single (or Multiple) Action, Multiple Methods to handle tightly-coupled functionality.
Particularly for small apps, and demos, it's a way to minimize XML configuration.
These days it might be more typical to remove most of the XML configuration and configure actions/methods individually using annotations.
Edit to reflect brand-new question.
I cannot duplicate the issue. Taking a minimal S2 app with a single line in menu.jsp and header.jsp and a stripped-down baseLayout.jsp results in the following: