This is the first time i have seen this system.
However it is only usefull if you know exactly what data you are getting
back from the database before hand. However if you get data back from a
system where you could be getting back n pieces of data. Well then you will
need to use some sort of loop for, while etc.
At the least you would need to split the template up into segments that
repeat etc
-----Original Message-----
From: Justin Wells [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 10, 1999 4:49 PM
To: [EMAIL PROTECTED]
Subject: Re: JSP vs Servlets?
Quoting Murray, Joseph C. ([EMAIL PROTECTED]):
> Being an old systems programmer who is starting to develop in JAVA
> and trying to determine the best set of tools to focus on,
> could you tell me what the template system does? Not conceptually,
> but how it is used as a tool.
You write 100% pure Java code to create a bunch of data that you
would like to return to the customer. Perhaps you do:
Hashtable context = new Hashtable();
Customer c = myDatabase.findCustomer(name);
context.put("Customer", c);
context.put("title", "Order page");
You do this in your regular Java servlet, in regular 100% pure Java
code, with full access to all the features, power, structure, and
benefits of the Java programming langauge.
The important thing is that you never write any HTML in your servlet.
Instead you do something like this:
OutputStream out = response.getOutputStream();
Template t = templateSystem.getTemplate("order-template");
t.execute(out, context);
which loads a template which you previously wrote and saved in a
text file under the name "order-template", and then writes it out
to the output stream you name, using the values in your hashtable
as the data to fill the template in with.
Notice that there is no HTML at all in your template, and as a result
the code you look like looks a lot like ordinary program code.
It isn't all cluttered up.
Similarly the template is not cluttered up with program code. It might
look something like this:
<html><head><title>Customer Information: $title</title></head><body>
<h1>Page for customer $Customer.Name
<table>
<tr><td>Product</td><td>Quantity</td></tr>
#foreach $order in $Customer.Orders {
<tr><td>$order.Product</td><td>$order.Quantity</td></tr>
}
Total owing: $Customer.Amount
</body></html>
This example uses WebMacro syntax, but the idea is largely the same for
FreeMarker or other template systems.
In the case of WebMacro, because it knows about Java beans, if your Customer
object is a bean then it automatically knows how to extract properties from
it like "Customer.Name" and "Customer.Amount". It also knows how to iterate
through anything like a list/iterator/vector/array/enumeration if that is
what the Customer.Orders property evaluates to.
FreeMarker differs from WebMacro at this point slightly. Instead of using
the Java beans spec to extract properties from objects, it requires you to
supply some adapter objects that adhere to FreeMarker interfaces. The end
result is the same though--your program data is accessible to the template.
You can download them and try them out. Many template systems are free
software
products that come with source code. WebMacro is her: www.webmacro.org.
Justin
- - -
WebMacro Servlet Framework
http://webmacro.org
___________________________________________________________________________
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
___________________________________________________________________________
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