hi,
my app has three packages public, sucurity (login,register,...) and private.
These packages correspond in that all actions within this package should be
displayed with the same menus. Therefore (i guess) i have (not yet, but
this is my idea) three base layouts from which to extend:
<definition name="public.layout" template="/layouts/publicLayout.ftl">
<put-attribute name="menu" value="/tiles/public/common_menu.ftl" />
<put-attribute name="body" value="/tiles/public/empty_body.ftl" />
</definition>
<definition name="security.layout" template="/layouts/securityLayout.ftl">
<put-attribute name="menu" value="/tiles/security/common_menu.ftl" />
<put-attribute name="body" value="/tiles/security/empty_body.ftl" />
</definition>
<definition name="private.layout" template="/layouts/privateLayout.ftl">
<put-attribute name="menu" value="/tiles/private/common_menu.ftl" />
<put-attribute name="body" value="/tiles/private/empty_body.ftl" />
</definition>
There seem to be three different ways to achieve my goal (with Tiles 2.1):
1) using Wildcards:
<definition name="package_*.body_*" extends"{1}.layout">
<put-attribute name="body" value="/tiles/{1}/{2}.ftl" />
</definition>
In that case my action mapping would have to provide the package name:
<package name="public" namespace="/public" ...>
...
<action...>
...
<result type="tiles">
package_public.body_nextPage <!-- hardcoded package name -->
</result>
</action>
</package>
Is there a better possiblity to replace the hardcoded package name with
something i don't have to type every time than extending the tiles-Result
with:
public class CustomTilesResult extends TilesResult{
public void setLocation( String location ) {
this.location =
"package_"+ServletActionContext.getActionMapping.getNamespace().substring(1)+
".body_"+location;
}
}
2)using EL:
<definition name="*" extends"${package}.layout">
<put-attribute name="body" value="/tiles/${package}/{1}.ftl" />
</definition>
This is much nicer than 1) because i don't have to code anything for the
action mappings. But is there an expression to compute the current package
with the EL? And how do i enable EL when i don't user the
http://tiles.apache.org/framework/tutorial/advanced/el-support.html
TilesServlet but the TilesListener (because i want
FreeMarker-integreation)?
Do i have access to the value stack when using the EL?
3)using a ViewPreparer to create the right menu:
in this version i wouldn't have my three base layouts but only one with a
viewpreparer that initialises the menu structure
<definition name="*" template="/layouts/baseLayout.ftl"
preparer="MenuViewPreparer">
<put-attribute name="menu" value="/tiles/dynamic_menu.ftl" />
<put-attribute name="body" value="/tiles/{1}.ftl" />
</definition>
So the MenuViewPrepare would by responsible to figure out which package is
used. That should work like this:
public void execute(TilesRequestContext tilesContext, AttributeContext
attributeContext) {
switch( ServletActionContext.getActionMapping.getNamespace() ) {
case: ...
{
Which approach is preferable? Is there an even better approach?
I don't understand the "if you need"-part of this statement
http://tiles.apache.org/framework/getting_started.html "if you need JSP
support, copy the tiles-jsp-VERSION.jar in the WEB-INF/lib directory of your
web application" .
Don't you always use the JSP-Tags at least in your baseLayout-File?
I guess i also have to include this when using FreeMarker because i call the
JSP-Tags from within FreeMarker too!?
Regards,
Stephan
--
View this message in context:
http://www.nabble.com/different-tiles-definition-depending-on-the-package-of-the-action-mapping--Struts-2--tp20207395p20207395.html
Sent from the tiles users mailing list archive at Nabble.com.