Here's an approach that has been working well for me....

I regard a JSP page as the "View" element in the MVC (Model/View/Controller)
architecture.  Swing uses a modified MVC architecture in which the view and
controller are combined into a single component called the "delegate".   In
my JSP applications I have use a modified MVC architecture in which the
controller, model, and maybe even some of part of the view, are combined
into a single component that I call the "toolkit".  I develop a toolkit for
practically every JSP page.  The toolkit contains almost all of my
application's Java code, very little code goes into the JSP.
At the top of my JSP pages I have a few lines that include a generic header,
like so...
        <html>

        <%-- toolkit used to build this page --%>
        <% String toolkitClassName=
"com.gt.anytime.toolkit.TeeTimeReviewToolkit"; %>

        <%-- common page header and initialization --%>
        <%@ include file="AnytimePageHeader.jsp" %>
        <% ReviewToolkit toolkit= (ReviewToolkit)_toolkit; %>
        ....
At the bottom of my JSP pages I have a couple of lines that include a
generic footer, like so...
        <%-- common page footer and clean up --%>
        <%@ include file="AnytimePageFooter.jsp" %>

AnytimePageHeader.jsp looks like this....
        <%-- imports --%>
        <%@ page imports="com.gt.anytime.*" %>
        ....<snip>

        /*
        Dispatch any incoming events.  If an event is dispatched then we're
        done since the event handler must generate a response.
        */
        if (EFCComponent.dispatch(pageContext))
                return;

        /*
        Initialize toolkit used to build this page.  A toolkit is a bean
that's
        used to build a JSP page.  I build a separate toolkit for each page
and
        pass the name of the toolkit in toolkitClassName.
        */
        AnytimeToolkit _toolkit= (AnytimeToolkit)
                Class.forName(toolkitClassName).newInstance();
        _toolkit.init(pageContext);

        // start processing page contents
                try {
                        if ((out= _toolkit.beginPage()) == null) {
                System.out.println("(out= _toolkit.beginPage()) == null");

System.out.println("toolkit="+_toolkit.getClass().getName());
                                return;
                }
        %>
        ...common HTML goes here...

AnytimePageFooter.jsp looks like this....
        ...common HTML goes here...
        </body>
        </html>

        <%  /********* complete page *********/
                } finally {
                        out= _toolkit.finalizePage();
                }

        %>

Now, after all that I can put almost all my code in the toolkit.  I add what
ever methods a designer needs for a particular page into the associated
toolkit.  The methods almost always return Strings (as you mentioned).  Some
methods may generate entire elements (like complete tables and such).  Some
methods just return individual data items.  Some toolkit methods return URLS
with are embedded in anchor tags or hidden form fields.  I have found it
very productive to encapsulate my Java code in these toolkits.

So, for instance, to include a person's name in a JSP is done like so...
        <%jsp:getProperty name="toolkit" property="Name"%>
...and the toolkit would have an associated method named getName().

BTW, I am playing a lot of games in these toolkits.  For instance, I have
started developing my own HTML component framework with Swing-like event
handling that is built on top of the ECS (Element Construction Set)
framework.  In this way I have been able to prototype and do rapid
development with JSP pages and at the same time encapsulate common HTML
components in a framework and reuse them.  My toolkits can use this
framework to generate huge chunks of HTML and then make the HTML available
to a JSP page.  I aspire to release my component framework later this year
as open source.

NOTE: I DO NOT put any business logic into a Toolkit.  NONE.  All business
logic is in EJB beans and/or Corba objects and/or RMI servers and the like.
Toolkits are only for encapsulating the Java code used to generate an
interface.  Toolkits get references to business objects and make the data
available to the JSP page.

hope I made some sense here,

ted stockwell

> -----Original Message-----
> From: Frank Starsinic [SMTP:[EMAIL PROTECTED]]
> Subject:      JSP Techniques for limiting java within the JSP (tms)
>
> One issue that keeps coming up is the combination of java code and HTML
> being
> put in the same
> place, i..e., the JSP page.
>
> What techniques are people using to limit the amount of java within a JSP.
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to