aspose file tools*
The moose likes JSP and the fly likes utility of Tiles for JSP layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "utility of Tiles for JSP layout" Watch "utility of Tiles for JSP layout" New topic
Author

utility of Tiles for JSP layout

David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
I wonder if the Tiles framework its really useful or not... I have been some hours trying to determine if its useful for a real production service to be developed in J2SE , but in comparison with the common "jsp:includes" I can't find a real advantage, specially since Struts is not used.

If anybody can figure any advantage of this way of arrange JSP layouts, please let me know! :-)
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Well, using JSP includes does not eliminate the amount of jsp pages that you need to create. Tiles is configurable so that it can plug in the appropriate jsp file into one template so that the look and feel is the same for every jsp that references that template in the tiles-defs.xml file. This gives the whole app the same look and feel and all the developer needs to deal with is page content.

Tiles is extremely useful even if you are not using struts.


No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
It also means that you don't have to worry about passing and/or encoding a parameter indicating what content should be in the page. Consider a site that has a header, footer, and content -- each of which can be changed. Which would you rather link to:

Option 'A':
www.mysite.com/myApp/layout.jsp?header=header1&content=content1&footer=footer1

or

Option 'B':
www.mysite.com/myApp/page1.do

?

Things for Option 'A' get even worse when the page contains HTML forms or items that require their own parameters.

Ugly URLs are the mother of invention -- Hence why Tiles and JSF were born.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
This gives the whole app the same look and feel and all the developer needs to deal with is page content


But if I have a header.jsp and a footer.jsp and then pages like page1.jsp, page2.jsp with the same html structure (copy-paste, maybe from a simple html file that could be considered a layout...), and in these pages I insert at the beginning the header.jsp and at the end footer.jsp with includes, I have the same look and feel also.

With Tiles I have the same but the developer far from deal only with page content needs to create the layout, and with Struts she needs to deal with the xml definitions, create a nonoperational Action and deal with the configuration of Struts. More complex, more or less same results.

Consider a site that has a header, footer, and content -- each of which can be changed


In this case I think we could have in page1.jsp an if condition. If the parameter we receive is header=header1, we will put the include with header1. If the parameter is header2, we will put the include with header2. And neither these parameters nor others we could be getting from a form need to appear in the URL if we use POST

Simpler solutions, almost same results. Yes, Tiles could be more nice to see but I can't see real advantages in comparison with the added complexity. Maybe if you need to change everything in an application after all the development... but even then you could change the includes with no difficulty... and in Tiles maybe you will need to change the definitions and the layouts and the struts configuration, I suppose it's not so easy.

I really WANT to find a good advantage to introduce Tiles in the project (must be useful, if people have developed it) but I am not able to find any!
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Valid points. Do it how you feel comfortable doing it. I once felt the same way but after I started using struts and tiles, I found it extremely easy to develop, manage, and maintain my sites that use tiles. This is just one person's opinion though.
Venu Navat
Ranch Hand

Joined: Dec 28, 2004
Posts: 30
You can create composite view from many smaller views using JSP includes. In
such case, you have to use include in each and every jsp page as per your
layput and such layout is repeated in each page. But what will you do when
your layout itself changes? You have to change the position of includes in
each and every page. Besause Jsp Include is not for defining a layout. It
simply allows content from one page to be used in another. Where is the
generic template?

Precisely this is where Tiles comes to our rescue.

The following is the official definitation of tiles:
The Tiles Framework is an advanced version of <jsp:include/> that comes
bundled with the Struts web application framework. Its purpose is to reduce
the duplication between jsp pages as well as make layouts flexible and easy
to maintain. It integrates with Struts using the concept of named views or
definitions.

Ofcourse, it is true that we don't have to use struts in order to use tiles
features.

Do not waste your precious time in trying to determine if its useful for a
real production service. It is definitely useful otherwise it would not have
got the importance that it has got. Even Microsoft is providing a feature
similar to Tiles in the upcoming version of ASP.NET.

Best wishes.


-Venu Navat
David Sappia
Greenhorn

Joined: Dec 29, 2004
Posts: 7
Thank you for your reply!

I spent this time because I wanted to know if it could be useful for this project that is starting now!

Now I understand better the pourpose of Tiles but I have concluded is not useful for this project: the layout is well defined in the specification, and the complexity of using Tiles without Struts is a waste of time (in my opinion) even if there is a small possibility that the client will ask in the future for a change in the layout. In that case, a change of the position of the includes in all the jsps will be the only problem so it will probably be just a one day work (compared with the many days making the team learn and implement Tiles, the added complexity of the application, and whoknows problems with JavaScript or whatever that could appear).

See you!
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
venu's post is true to point. This is what I've been trying to say all along. If you feel that this isn't the right time to implement tiles into a project then so be it. I can relate to that. However, I strongly encourage you to investigate Tiles in more detail for future projects. I promise you it is not a waste of time.
 
wood burning stoves
 
subject: utility of Tiles for JSP layout