File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Design patterns for templates (or something like that ...) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Design patterns for templates (or something like that ...)" Watch "Design patterns for templates (or something like that ...)" New topic

Design patterns for templates (or something like that ...)

Matteo Di Furia
Ranch Hand

Joined: Jun 20, 2008
Posts: 102
Hello everyone,

I'm developing a webapp which has a web structure similar to a portal (well, it actually is a portal!).
Like in every other portal on the web, there will be a great number of pages which all have the same structure, i.e. an header, a navigation bar, left and right menu's, a footer and so on. The content of every singular module is generated dinamically and imported in every JSP, so no problem at this.
What is making me worrying is the general structure of the page, which must be identical for every page on the portal. I'd like to use or write a template engine (or something like that) to handle the structure of the page (dimensions of header, width of menu's, position of some elements and so on).
This is not an hard job actually, I can think of more than one solutions to this, but I'd like to do it in the "proper" way. I.e. is there a well known, maybe "standard" engine out there to handle these kind of things, or maybe a design pattern you can apply to design it in the right way ? I would not like to discover that what I implement is not good for some reason (maybe not scalable, not flexible or whatever).
Just to make things more clear, I'll provide a stupid example. I got a page named header.jsp in which is written (wohoo, big surprise!) the content of the header for every page. The header is included in every page with :

The header has a width which is obviously equal for each page, but every page has to adjust the width of the table of the main content to fit the header. If I decide to change the header width, I must change each jsp to fit the new width. I could extrapolate a set of variables that organize the structure of the jsp and then set those variables values for each jsp, but then I have to handle these variables in some way, and it seems to me I would go with a private implementation that could result sooner or later in a bad design which would require a total reorganization of the whole portal.
I'm basically looking for design patterns for portals templates manipulation.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

Observation 1: tag files would be a cleaner implementation than includes for the header.

Observation 2: the rest sounds like more of a CSS issue than JSP one.
[ July 12, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Matteo Di Furia
Ranch Hand

Joined: Jun 20, 2008
Posts: 102
Hi Bibeault,

I know what I'm near to write will sound like a blasfemy, but ... I use CSS only for graphic management of the components, dimensions and position of modules are organized via HTML tables ...
And if I could ask, what do you mean with tag files ? Could you provide me an example ? Maybe I know those with another name, but whatever.
Thank you for your help. By the way, I'm browsing the web for this problem and I found something about the Composite View pattern, do you think this could be a reasonable solution ? (I'm still reading on it, don't know if it's related to this problem or not)
I agree. Here's the link:
subject: Design patterns for templates (or something like that ...)
It's not a secret anymore!