You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Sameera Gayan <sa...@rcapl.com> on 2011/04/04 13:29:14 UTC

apache + tiles2 layout problem

Hi All,

First of all, pardon me if I'm asking a wrong question here.. new to the
mailing list

I have the following tiles configuration file



<tiles-definitions>
    <definition name="base" template="/includes/layout.jsp">
        <put-attribute name="header" value="/includes/header.jsp" />
        <put-attribute name="menu" value="/includes/menu.jsp" />
        <put-attribute name="footer" value="/includes/footer.jsp" />
    </definition>
    <definition name="home" extends="base">
        <put-attribute name="contentBody" value="/home/view.jsp" />
    </definition>
</tiles-definitions>
and to display "view.jsp" page I have another page called "home.jsp" and it
has the following code (only)

//home.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<tiles:insertDefinition name="home" />
and the problem here is, If i want to load "edit.jsp" page with same layout,
I need to repeat this part in tiles.xml

<definition name="editbase" extends="base">
            <put-attribute name="contentBody" value="/home/edit.jsp" />
</definition>
and create a file called "editbase.jsp" and call it. (repeating the above
code)

I'm just wondering is this the correct way or can I do something like

<tiles-definitions>
        <definition name="base" template="/includes/layout.jsp">
            <put-attribute name="header" value="/includes/header.jsp" />
            <put-attribute name="menu" value="/includes/menu.jsp" />
            <put-attribute name="footer" value="/includes/footer.jsp" />
        </definition>
        <definition name="home" extends="base">
            <put-attribute name="contentBody" value="/home/view.jsp" />
            <put-attribute name="contentBody" value="/home/edit.jsp" />
        </definition>
</tiles-definitions>
and load the page accordingly.. I think my question is clear

I'm using apache tiles 2.2.2

thanks in advance

cheers

sameera

Re: apache + tiles2 layout problem

Posted by Sameera Gayan <sa...@rcapl.com>.
hi Antonio

Thanks for the link, will check that out

thanks

cheers

sameera

On Tue, Apr 5, 2011 at 3:17 AM, Antonio Petrelli <antonio.petrelli@gmail.com
> wrote:

> 2011/4/5 Sameera Gayan <sa...@rcapl.com>
>
>> Thanks for the reply, I have been working with java web projects around 6
>> months and I think I can manage basics (JEE). :D.. And I'll be thankful if
>> you could direct me to some resources / examples of 'TilesDispatchServlet'
>> usage examples
>>
>>
> Currently the only example I am aware of is tiles-test webapp, available in
> Tiles distribution or here;
> http://svn.apache.org/repos/asf/tiles/framework/trunk/tiles-test-pom
> (it is a modularized Maven project with three modules, tiles-test contains
> the "real" code you need)
>  <http://svn.apache.org/repos/asf/tiles/framework/trunk/tiles-test-pom>It
> has a single link that uses the definition filter: "Test Tiles Definition
> Filter" (yeah I know, there's a typo, not "definition" but "decoration").
>
> HTH
> Antonio
>

Re: apache + tiles2 layout problem

Posted by Antonio Petrelli <an...@gmail.com>.
2011/4/5 Sameera Gayan <sa...@rcapl.com>

> Thanks for the reply, I have been working with java web projects around 6
> months and I think I can manage basics (JEE). :D.. And I'll be thankful if
> you could direct me to some resources / examples of 'TilesDispatchServlet'
> usage examples
>
>
Currently the only example I am aware of is tiles-test webapp, available in
Tiles distribution or here;
http://svn.apache.org/repos/asf/tiles/framework/trunk/tiles-test-pom
(it is a modularized Maven project with three modules, tiles-test contains
the "real" code you need)
<http://svn.apache.org/repos/asf/tiles/framework/trunk/tiles-test-pom>It has
a single link that uses the definition filter: "Test Tiles Definition
Filter" (yeah I know, there's a typo, not "definition" but "decoration").

HTH
Antonio

Re: apache + tiles2 layout problem

Posted by Sameera Gayan <sa...@rcapl.com>.
Hi @Antonio

Thanks for the reply, I have been working with java web projects around 6
months and I think I can manage basics (JEE). :D.. And I'll be thankful if
you could direct me to some resources / examples of 'TilesDispatchServlet'
usage examples

thanks in advance

cheers

sameera


On Mon, Apr 4, 2011 at 8:13 AM, Antonio Petrelli <antonio.petrelli@gmail.com
> wrote:

> I am replying in the mailing list since it is more appropriate.
>
> 2011/4/4 Sameera Gayan <sa...@rcapl.com>
>
> > Thanks for the quick replay. (wow.. that was fast) . I have gone through
> > the 'TilesDecorationFilter' and seems like it matches my requirement. It
> > would be a great help if you can direct me to some examples of applying
> the
> > concept.. Since I'm new to both java and Tiles, its little hard for me to
> > figure out by my own..
>
>
> I suppose that the best thing to do is learning from a tutorial. If you are
> new to Java at all, I suggest to start here:
> http://www.roseindia.net/java/
> <http://www.roseindia.net/java/>Better know the basics of Java and Java EE
> (it's called "JEE 5" in the page linked above), after that you are ready
> for
> Tiles.
>
> Antonio
>

Re: apache + tiles2 layout problem

Posted by Antonio Petrelli <an...@gmail.com>.
I am replying in the mailing list since it is more appropriate.

2011/4/4 Sameera Gayan <sa...@rcapl.com>

> Thanks for the quick replay. (wow.. that was fast) . I have gone through
> the 'TilesDecorationFilter' and seems like it matches my requirement. It
> would be a great help if you can direct me to some examples of applying the
> concept.. Since I'm new to both java and Tiles, its little hard for me to
> figure out by my own..


I suppose that the best thing to do is learning from a tutorial. If you are
new to Java at all, I suggest to start here:
http://www.roseindia.net/java/
<http://www.roseindia.net/java/>Better know the basics of Java and Java EE
(it's called "JEE 5" in the page linked above), after that you are ready for
Tiles.

Antonio

Re: apache + tiles2 layout problem

Posted by Antonio Petrelli <an...@gmail.com>.
2011/4/4 Sameera Gayan <sa...@rcapl.com>

> First of all, pardon me if I'm asking a wrong question here.. new to the
> mailing list
>

It's correct :-)


>
> I have the following tiles configuration file
>
>
>
> <tiles-definitions>
>    <definition name="base" template="/includes/layout.jsp">
>        <put-attribute name="header" value="/includes/header.jsp" />
>        <put-attribute name="menu" value="/includes/menu.jsp" />
>        <put-attribute name="footer" value="/includes/footer.jsp" />
>    </definition>
>    <definition name="home" extends="base">
>        <put-attribute name="contentBody" value="/home/view.jsp" />
>    </definition>
> </tiles-definitions>
> and to display "view.jsp" page I have another page called "home.jsp" and it
> has the following code (only)
>
> //home.jsp
>
> <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
> <tiles:insertDefinition name="home" />
> and the problem here is, If i want to load "edit.jsp" page with same
> layout,
> I need to repeat this part in tiles.xml
>
> <definition name="editbase" extends="base">
>            <put-attribute name="contentBody" value="/home/edit.jsp" />
> </definition>
> and create a file called "editbase.jsp" and call it. (repeating the above
> code)
>
> I'm just wondering is this the correct way or can I do something like
>
> <tiles-definitions>
>        <definition name="base" template="/includes/layout.jsp">
>            <put-attribute name="header" value="/includes/header.jsp" />
>            <put-attribute name="menu" value="/includes/menu.jsp" />
>            <put-attribute name="footer" value="/includes/footer.jsp" />
>        </definition>
>        <definition name="home" extends="base">
>            <put-attribute name="contentBody" value="/home/view.jsp" />
>            <put-attribute name="contentBody" value="/home/edit.jsp" />
>        </definition>
> </tiles-definitions>
> and load the page accordingly.. I think my question is clear
>

You cannot put two attribute values to one attribute. Never tried, but I
think the last one wins.
So the first part of your code works.

Correct if I am wrong, but do you want a website that has the same layout
everywhere, with the exception of "contentBody" part?
If yes you might be interested in TilesDecorationFilter:
http://tiles.apache.org/framework/tutorial/advanced/utils.html

<http://tiles.apache.org/framework/tutorial/advanced/utils.html>Antonio