struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Nenning <Christoph.Nenn...@lex-com.net>
Subject Tiles with Annotations
Date Thu, 02 Jan 2014 16:02:49 GMT
Dear List,


in our applications we often use the convention-plugin together with 
tiles-plugin (tiles 2).

convention-plugin has the advantage that it is not necessary to put an 
entry in struts.xml for each action. So struts.xml usually is very small.
But we still have tiles.xml which needs an entry for each action. In big 
applications that file becomes huge and hard to maintain.

To fix that I created a bunch of Annotations and a struts2 result to be 
able to create tile defs with annotations.


It would take me some time to turn that into a proper framework patch.

Now my question is: Do you like that stuff?



Sample application code:


--------------------------------------------
tiles.xml
--------------------------------------------
<tiles-definitions>
    <definition name=".default-layout" template=
"/WEB-INF/tiles/layout/layout.jsp">
        <put-attribute name="titleMsgKey" value=".titleMsgKey" />
        <put-attribute name="content" value=".content" />
    </definition>

    <!-- no more entries ! -->
    <!-- except you have several layouts -->
</tiles-definitions>


--------------------------------------------
SampleAction
--------------------------------------------
@Result(name=SampleAction.INPUT, type="tiles-annotation")
@TileDef(
        extend=".default-layout",
        attributes={
                @TileAttribute(name="titleMsgKey", value="text.key.test"),
                @TileAttribute(name="content", value=
"/WEB-INF/tiles/test/test.jsp")
        }
)
public class SampleAction extends ActionSupport {
...
}


--------------------------------------------
web.xml
--------------------------------------------

        <!-- a parameter for TilesListener is required which I wrapped in 
a specialized context listener -->
        <!-- that parameter is:
                <param-name>
org.apache.tiles.factory.TilesContainerFactory.MUTABLE</param-name>
                <param-value>true</param-value>
        -->
        <listener>
                <listener-class>
 org.apache.struts2.tiles.StrutsTilesAnnotationsListener
                </listener-class>
                <init-param>
                        <param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
                        <param-value>/WEB-INF/classes/tiles.xml</
param-value>
                </init-param>
        </listener>



regards,
Christoph

This Email was scanned by Sophos Anti Virus

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message