How to make jsp functions(?)

L

loggin

Hi,

Having worked with several web dev languages I've gotten use to
designing sites with particular style and that allow for quick and
easy template updates (some sites have had over 12000 pages) usually
the templates are controlled from one template(skin) file with the
pages individual content being placed into zones/regions defined in
the template, however so far the closest I've come to finding a
solution in jsp means chopping up my template into several files and
then using includes to place them in my page, so it looks sumfin like:

<%@ include file="top.jsp" %>
<h1>Welcome Title</h1>
<%@ include file="nav.jsp" %>
My main content
<%@ include file="ads.jsp" %>
<%@ include file="footer.jsp" %>

but although the skin is centrally controlled its not ideal as the
file is now split across several files and also if I wanted my main
content to appear before my navigation I would have to go into each
individual file still and reorganise it manually, what I'm really
looking for is a technique to encapsulate my content in a function
like container which is then lifted and placed into the zones defined
in my template with a getFunction like call, does anyone know of
anything already in existence ?

Below is an example of I would ideally like to structure my files,
well not quite so ideal as I have to put the doctype at the very top
of my code which is just a pain, if I can't find something like I'm
going to start trying to write my own tag to do it.

<!-- mypage.jsp -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html40/strict.dtd">
<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="/WEB-INF/tlds/custom.tld" prefix="r" %><r:Function
id="header" return="true">
<h1>Page Specific Header Content</h1>
</r:Function>

<r:Function id="content" return="true">
Page Specific Content
<r:Set name="{pagecontext.title}" value="Dynamic Title" />
</r:Function>

<r:Function id="title" return="true">
Page Specific Title - <r:Get name="{pagecontext.title}" />
</r:Function>

<r:Test name="request.template" test="==" value="1">
<%@ include file="temp.jsp" %>
</r:Test>
<r:Test name="request.template" test="==" value="2">
<%@ include file="temp2.jsp" %>
</r:Test>
<!-- end mypage.jsp -->



<!-- temp.jsp -->

<%@ include file="/assets/inc/outerhtml.jsp" %>
<%@ include file="/assets/inc/functions.jsp" %>
<%@ include file="nav.jsp" %>
<%@ include file="footer.jsp" %>
<html>
<head>
<title><r:getFunction name="title" /></title>
<%@ include file="/assets/inc/styles.jsp" %>
<%@ include file="/assets/inc/scripts.jsp" %>

</head>
<body>
<div>
<div>
<r:getFunction name="header" />
</div>
<div>
<r:getFunction name="nav" />
</div>
<div>
<r:getFunction name="content" />
</div>
<div>
<r:getFunction name="footer" />
</div>
</div>
</body>
</html>
<!-- end temp.jsp -->



<!-- temp2.jsp -->

<%@ include file="/assets/inc/outerhtml.jsp" %>
<%@ include file="/assets/inc/functions.jsp" %>
<%@ include file="nav.jsp" %>
<%@ include file="footer.jsp" %>
<html>
<head>
<title><r:getFunction name="title" /></title>
<%@ include file="/assets/inc/styles.jsp" %>
<%@ include file="/assets/inc/scripts.jsp" %>

</head>
<body>
<div>
<div>
<r:getFunction name="header" />
</div>
<div>
<div style="float:left;">
<r:getFunction name="nav" />
</div>
<div style="float:right;">
<div>
<r:getFunction name="content" />
</div>
<div>
<r:getFunction name="footer" />
</div>
</div>
</div>
</div>
</body>
</html>
<!-- end temp2.jsp -->
 
E

enrique

It's been awhile for me, but I'll try to impart another possible
design.

With regards to easily replaceable content, you could continue to use
just one JSP file instead of splitting it up. Your content could be
pulled in by a servlet (or another JSP) in-place of where the
substitution would occur.

For an easy-to-replace design, I would think you'd be fine with
standard CSS. No server-side technology need be involved.

You mentioned creating custom tags, which is not a bad idea.

You may get lots of responses, each recommending a more sophisticated
document publishing application.

epp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top