On Tue, Apr 20, 1999 at 04:51:22PM +0200, Robb Shecter wrote:
> Paul Philion wrote:
> > Greetings...
> > I have a question: Why use a "HTML generator" when there are several
> > templete evaluation engines available?
> Hi.
> What's a typical template evaluation system?  How does the code look
> that servlet programmers must write when they use it?

        A template system separates the HTML/formatting from the
logic. You have a template file with straight HTML and some special
tags, IE:

<HTML>
<HEAD><TITLE>&[title];</TITLE></HEAD>
</HTML>

        The "&[title];" bit is a tag.

        In your code, you fill in a hash table with the name/value
pairs, then call the template parser:

HashDataSet hds = new HashDataSet();
hds.putVariable("title", "Test Page");
FileReader reader = new FileReader("test.tmpl");
Writer writer = resp.getWriter();
TemplateFiller.fill(hds, writer, reader);

        The result is:

<HTML>
<HEAD><TITLE>Test Page</TITLE></HEAD>
</HTML>

        There are tags for simple substitution, as above, for
conditional inclusion (IE, if defined, show this section. If not
defined, show this section.), and for repetition (Here's a Vector,
each element is a hash table of values, repeat this block for each
element in the Vector.).

        The biggest advantage is that the formatting is all outside
the code; you can have people who know HTML but not Java doing the
page layout and surrounding copy/graphics work. You can also strip
the template down to a bare minimum during development and testing.

        IMHO, templates are much better -- easier, simpler, and
cleaner -- than element construction. They enhance encapsulation
and don't lock your logic into a single graphical look.



        [Examples use the template system in the Apache JServ project's
utilities archive.]

--
Robert Crawford                 [EMAIL PROTECTED]
http://www.iac.net/~crawford

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to