You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Ken McWilliams <ke...@gmail.com> on 2012/12/06 08:49:13 UTC

Seeking Struts2 Tiles3 conventions plugin advice

Struts2 has a conventions plugin which I find very useful. Simply it
extracts a portion of the URL as a "namespace" and an "action".

Some basic background concerning rendering the result.
===============
If the url is http://contextroot/namespace/my-action

the namespace would be "/namespace" and the action would be "my-action"

By default conventions will look for a view called:
/WEB-INF/content/namespace/my-action.*

Where "*" may be of several types jsp, ftl, vm,...
===============
Now to the point, I want to integrate tiles3 into this flow.

So far I've got it so a definition called (namespace + "#" + action) is
sent to tiles. So I do have rudimentary integration.

IE:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD
Tiles Configuration 3.0//EN" "
http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
    <definition name="/test"
template="/WEB-INF/content/template/template.jsp">
        <put-attribute name="head"
value="/WEB-INF/content/template/head.jsp"/>
        <put-attribute name="header"
value="/WEB-INF/content/template/header.jsp"/>
        <put-attribute name="body"
value="/WEB-INF/content/template/body.jsp"/>
        <put-attribute name="footer"
value="/WEB-INF/content/template/footer.jsp"/>
    </definition>
    <definition name="REGEXP:(.*)#(.*)"  extends="/test">
        <put-attribute name="body" value="/WEB-INF/content{1}/{2}"/>
    </definition>
</tiles-definitions>

So, does anyone have any ideas on how templates should be determined, if we
are going to try and apply conventions to tiles?

What are some good practices that you think people should follow?

Here are some ideas for rules:
- at startup /WEB-INF/content is searched for files called template.* or
maybe tiles-template.* if found a definition is created with the name of
that namespace ("/" if at the base)
- all namespaces will have an associated tiles definition, where if a
definition is not explicitly created from a template, it will inherit from
the definition of the first template up the hierarchy.
- packages will be searched for tiles-* files if a files is found not
called tiles-template but rather tiles-footer.jsp for example, the
definition for the package will be given a put attribute with the name
"footer" and provided a value pointing at the tiles-body.jsp file.
- body content will be assumed to be the action name and the file type will
be assumed to be (a user defined parameter)

This is only an example.

Struts2 aside, if you were to generate definitions from a url and content
layout what scheme would you use?

Re: Seeking Struts2 Tiles3 conventions plugin advice

Posted by Ken McWilliams <ke...@gmail.com>.
Thank you this looks very similar to what I've got currently.

I'm not familiar with either of these technologies, do either of them have
a conventions based templating that I can ape?

What I want to do is more challenging. I want developers to be able to
create a file called "tiles-template.*" and have that file be parsed at
start up and automatically generate tiles definitions who's tiles
attributes are found in the same folder (files called "tiles-*.*).  Sub
folders may create their own ("tiles-*.*") this would then cause an
extension of the parent definition and override those attributes.

Just like the link to the page you provided the main body content does not
need to have any special prefix and so by convention the developer must
have a tiles:insertAttribute with a value of "body" in all their templates.

It will be a while before I get the time to move forward on this but that
is the general idea.


On Thu, Dec 6, 2012 at 10:02 PM, Nicolas LE BAS <ma...@nlebas.net> wrote:

> I have no fixed opinion on this.
>
> However, I like the file structure usually adopted by grails, or
> spring-roo. There is a suggestion of a generic tiles configuration file
> for that structure here:
> http://forum.springsource.org/showthread.php?94670-Tiles-with-wildcards
>
> Hope this helps,
> Nick
>
> On 12-12-06 02:49 AM, Ken McWilliams wrote:
> > Struts2 has a conventions plugin which I find very useful. Simply it
> > extracts a portion of the URL as a "namespace" and an "action".
> >
> > Some basic background concerning rendering the result.
> > =============== If the url is http://contextroot/namespace/my-action
> >
> > the namespace would be "/namespace" and the action would be
> > "my-action"
> >
> > By default conventions will look for a view called:
> > /WEB-INF/content/namespace/my-action.*
> >
> > Where "*" may be of several types jsp, ftl, vm,... ===============
> > Now to the point, I want to integrate tiles3 into this flow.
> >
> > So far I've got it so a definition called (namespace + "#" + action)
> > is sent to tiles. So I do have rudimentary integration.
> >
> > IE:
> >
> > <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE tiles-definitions
> > PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration
> > 3.0//EN" " http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
> > <tiles-definitions> <definition name="/test"
> > template="/WEB-INF/content/template/template.jsp"> <put-attribute
> > name="head" value="/WEB-INF/content/template/head.jsp"/>
> > <put-attribute name="header"
> > value="/WEB-INF/content/template/header.jsp"/> <put-attribute
> > name="body" value="/WEB-INF/content/template/body.jsp"/>
> > <put-attribute name="footer"
> > value="/WEB-INF/content/template/footer.jsp"/> </definition>
> > <definition name="REGEXP:(.*)#(.*)"  extends="/test"> <put-attribute
> > name="body" value="/WEB-INF/content{1}/{2}"/> </definition>
> > </tiles-definitions>
> >
> > So, does anyone have any ideas on how templates should be determined,
> > if we are going to try and apply conventions to tiles?
> >
> > What are some good practices that you think people should follow?
> >
> > Here are some ideas for rules: - at startup /WEB-INF/content is
> > searched for files called template.* or maybe tiles-template.* if
> > found a definition is created with the name of that namespace ("/" if
> > at the base) - all namespaces will have an associated tiles
> > definition, where if a definition is not explicitly created from a
> > template, it will inherit from the definition of the first template
> > up the hierarchy. - packages will be searched for tiles-* files if a
> > files is found not called tiles-template but rather tiles-footer.jsp
> > for example, the definition for the package will be given a put
> > attribute with the name "footer" and provided a value pointing at the
> > tiles-body.jsp file. - body content will be assumed to be the action
> > name and the file type will be assumed to be (a user defined
> > parameter)
> >
> > This is only an example.
> >
> > Struts2 aside, if you were to generate definitions from a url and
> > content layout what scheme would you use?
> >
>
>

Re: Seeking Struts2 Tiles3 conventions plugin advice

Posted by Nicolas LE BAS <ma...@nlebas.net>.
I have no fixed opinion on this.

However, I like the file structure usually adopted by grails, or
spring-roo. There is a suggestion of a generic tiles configuration file
for that structure here:
http://forum.springsource.org/showthread.php?94670-Tiles-with-wildcards

Hope this helps,
Nick

On 12-12-06 02:49 AM, Ken McWilliams wrote:
> Struts2 has a conventions plugin which I find very useful. Simply it 
> extracts a portion of the URL as a "namespace" and an "action".
> 
> Some basic background concerning rendering the result. 
> =============== If the url is http://contextroot/namespace/my-action
> 
> the namespace would be "/namespace" and the action would be
> "my-action"
> 
> By default conventions will look for a view called: 
> /WEB-INF/content/namespace/my-action.*
> 
> Where "*" may be of several types jsp, ftl, vm,... =============== 
> Now to the point, I want to integrate tiles3 into this flow.
> 
> So far I've got it so a definition called (namespace + "#" + action)
> is sent to tiles. So I do have rudimentary integration.
> 
> IE:
> 
> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE tiles-definitions
> PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration
> 3.0//EN" " http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> 
> <tiles-definitions> <definition name="/test" 
> template="/WEB-INF/content/template/template.jsp"> <put-attribute
> name="head" value="/WEB-INF/content/template/head.jsp"/> 
> <put-attribute name="header" 
> value="/WEB-INF/content/template/header.jsp"/> <put-attribute
> name="body" value="/WEB-INF/content/template/body.jsp"/> 
> <put-attribute name="footer" 
> value="/WEB-INF/content/template/footer.jsp"/> </definition> 
> <definition name="REGEXP:(.*)#(.*)"  extends="/test"> <put-attribute
> name="body" value="/WEB-INF/content{1}/{2}"/> </definition> 
> </tiles-definitions>
> 
> So, does anyone have any ideas on how templates should be determined,
> if we are going to try and apply conventions to tiles?
> 
> What are some good practices that you think people should follow?
> 
> Here are some ideas for rules: - at startup /WEB-INF/content is
> searched for files called template.* or maybe tiles-template.* if
> found a definition is created with the name of that namespace ("/" if
> at the base) - all namespaces will have an associated tiles
> definition, where if a definition is not explicitly created from a
> template, it will inherit from the definition of the first template
> up the hierarchy. - packages will be searched for tiles-* files if a
> files is found not called tiles-template but rather tiles-footer.jsp
> for example, the definition for the package will be given a put
> attribute with the name "footer" and provided a value pointing at the
> tiles-body.jsp file. - body content will be assumed to be the action
> name and the file type will be assumed to be (a user defined
> parameter)
> 
> This is only an example.
> 
> Struts2 aside, if you were to generate definitions from a url and
> content layout what scheme would you use?
>