You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christoph Nenning <Ch...@lex-com.net> on 2014/01/02 17:02:49 UTC

Tiles with Annotations

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

Re: Tiles with Annotations

Posted by Christoph Nenning <Ch...@lex-com.net>.
> 
> And soon it will be integrated with S2 as well :-)
> 
> https://issues.apache.org/jira/browse/WW-4161
> 
> 

Interesting that there is something happening in that direction.

I commented in JIRA an posting it here again:

convention-plugin provides a set of own annotations like @Action or 
@Result to override the convention. I think it would be nice to have such 
annotations for tiles as well. 


regards,
Christoph

This Email was scanned by Sophos Anti Virus

Re: Tiles with Annotations

Posted by Lukasz Lenart <lu...@apache.org>.
And soon it will be integrated with S2 as well :-)

https://issues.apache.org/jira/browse/WW-4161


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2014/1/2 Ken McWilliams <ke...@gmail.com>:
> I arrived at the same conclusion when trying to remove my tiles
> configuration. I upgraded to tiles 3 in the process and wrote a custom
> result handler (sorry a custom "unknown result handler"). It is invoked
> when conventions isn't able to find an appropriate result.
>
>  Here is a stack overflow Q & A which covers that process: "How to
> Integrate Struts Conventions with Tiles such that the benefit of
> conventions is maintained" http://stackoverflow.com/q/16116142/514065
>
>
>
> On Thu, Jan 2, 2014 at 9:16 AM, Paul Benedict <pb...@apache.org> wrote:
>
>> Annotations usually help augment the class being annotated. I don't think
>> annotating a Struts action with Tile definitions is very appropriate for
>> this purpose. The purposes are just very different. XML seems more
>> appropriate than annotations here.
>>
>>
>>
>>
>> On Thu, Jan 2, 2014 at 10:02 AM, Christoph Nenning <
>> Christoph.Nenning@lex-com.net> wrote:
>>
>> > 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
>> >
>>
>>
>>
>> --
>> Cheers,
>> Paul
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Tiles with Annotations

Posted by Ken McWilliams <ke...@gmail.com>.
I arrived at the same conclusion when trying to remove my tiles
configuration. I upgraded to tiles 3 in the process and wrote a custom
result handler (sorry a custom "unknown result handler"). It is invoked
when conventions isn't able to find an appropriate result.

 Here is a stack overflow Q & A which covers that process: "How to
Integrate Struts Conventions with Tiles such that the benefit of
conventions is maintained" http://stackoverflow.com/q/16116142/514065



On Thu, Jan 2, 2014 at 9:16 AM, Paul Benedict <pb...@apache.org> wrote:

> Annotations usually help augment the class being annotated. I don't think
> annotating a Struts action with Tile definitions is very appropriate for
> this purpose. The purposes are just very different. XML seems more
> appropriate than annotations here.
>
>
>
>
> On Thu, Jan 2, 2014 at 10:02 AM, Christoph Nenning <
> Christoph.Nenning@lex-com.net> wrote:
>
> > 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
> >
>
>
>
> --
> Cheers,
> Paul
>

Re: Tiles with Annotations

Posted by Paul Benedict <pb...@apache.org>.
Annotations usually help augment the class being annotated. I don't think
annotating a Struts action with Tile definitions is very appropriate for
this purpose. The purposes are just very different. XML seems more
appropriate than annotations here.




On Thu, Jan 2, 2014 at 10:02 AM, Christoph Nenning <
Christoph.Nenning@lex-com.net> wrote:

> 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
>



-- 
Cheers,
Paul