I am not sure if I understand your question correctly but
have you check the struts-template web application example
that comes with the struts framework? This might give you
a good indication on how to build a good template using Struts.

You can also create custom tags instead of having Java in your jsp...

Mario L.

>>> [EMAIL PROTECTED] 04/19/01 11:27AM >>>
I'm trying to decide how to structure our app.  We want to use templates to
separate the layout from the content, and we want to use the Struts
framework to separate the business logic from the presentation.  I've been
converting several parts of our site and am happy with the results.
However, we also want to, as much as possible, separate out reusable parts
of the presentation into separate JSP pages (sort of "components").  For
example, we have a header and have it separated into header.jsp.  This JSP
page can take parameters and can also adjust itself based on its
"environment", that is, what it finds in the request.  But to do so, it has
a bunch of Java in the JSP (it was also developed before I came and without
an eye to keeping the business logic separate).

What I'd like to do is change the header.jsp to pull the Java out.  I see
several possible ways to do that.  One is to essentially develop an Action
that sets up for the JSP and then forwards to the JSP.  So, for example,
that would change the code in my current pages like:

<jsp:include page="/components/header.jsp" flush="true"><jsp:param
name="atab" value="main"/></jsp:include>

to look like:

<jsp:include page="/components/header.do" flush="true"><jsp:param
name="atab" value="main"/></jsp:include>

but I'm not sure what the performance implications of this would be.  That
is, what is the difference between a <jsp:include> of a JSP page versus an
Action.  In the case of the Action, it would be routed through the app
server (resin in our case...for now), through the ActionServlet and Action,
and then forwarded to the JSP.  (Now that I think of it, I'm not sure this
would even work, but I think it should.)  In the JSP case, is it also routed
through the app server, so the only difference is where the business logic
is done?

Another idea I have is to create one or more custom tags that will set up
for the header JSP.  That way, the JSP could be included just as header.jsp,
but the Java and business logic would have been extracted to the custom
tag(s).  The negative of this is it is a departure from the Struts
architecture and puts the business logic in a sort of unexpected place.

The last idea I had was to somehow cause the Action for the enclosing page
(that is, the page that does the <jsp:include> of the header) to do the
logic and setup necessary for the header.  Then the header would just get
what it needs from the request and could remain a JSP, not an Action.  The
negative of this is that the logic for the header would be performed by the
Actions of all the pages, although it could be included in the BaseAction
that I extend for my Actions.

BTW, we have one motivation that others may not have: we are developing an
example application that will be given to our customers to base their app
on.  So we want to structure things in the best, most understandable way.

Thanks for any help,
Scott

Reply via email to