29.06.2009: Announcement: next version available soon, with simplified form processing and dependency management, see Changelog
ztemplates
ztemplates is a easy to learn open source web framework based on Java jdk1.5 or later. It is licensed under the Apache 2.0 License
It runs in any Servlet Spec 2.4 or later compliant web-container, like apache tomcat 6
.
ztemplates supports Apache Velocity
, JSP and FreeMarker
out of the box and can easily be extended to your preferred rendering technology.
It has annotation based support for JavaScript libraries. The AJAX form support is based on the Yahoo User Interface (YUI)
JavaScript library. Upcoming version switched to jquery
.
About the author
ztemplates is written and maintained by Gerd Ziegler
, a freelance Java Software pro from the Munich/Germany area.
I am currently seeking for a Java/J2EE projekt in the Munich area, so if you are looking for a Java architect/developer or need some on-site training in ztemplates please follow this link to get my contact data
.
Features
- based on annotations and autodiscovery
- no XML configuration
- statefree
- no constraints on the url format
- REST
-ful urls: define variables in the url and map them to pojo properties
- robust refactoring-safe urls by two way pojo-to-url and url-to-pojo annotation based mapping
- annotation based AJAX and JavaScript support. Declare needed css, javascript in annotations.
- automatic javascript aggregation and compression (JSMin and gzip)
- selfcontained components. Components can be packaged into a jar and installed by dropping the jar into WEB-INF/lib
- flexible rendering engine supports major templating technologies like JSP, Velocity, FreeMarker
- ztemplates is a filter that passes through urls it cannot match so you can transparently add it to or remove it from your existing webapp.
In a nutshell
Specify the view layout using your preferred templating technology (Velocity, FreeMarker, JSP...)
HelloWorldView.vm:
<html>
<h1>$message</h1>
$includedView
</html>
|
/**
* Holds data for template, instantiated and rendered by the action
*
* uses velocity, ztemplates uses template file called 'HelloWorldView.vm'
*/
@ZRenderer(ZVelocityRenderer.class)
public class HelloWorldView {
private final String message;
private final AnotherView includedView;
public HelloWorldView(String message) {
this.message = message;
this.includedView = new AnotherView();
}
@ZExpose //now can use 'message' in template
public String getMessage() {
return message;
}
//can use 'includedView' in template, exposes the <b>rendered</b>
//view to the template, as a String
@ZExpose(render=true)
public AnotherView getIncludedView() {
return includedView;
}
}
|
/**
* action matches all urls like '/helloworld/*' example: '/helloworld/myText'
*/
@ZMatch("/helloworld/${message}")
public class HelloWorldAction {
private String message;
//ztemplates calls this with the value from the url
//property name matches name from @ZMatch annotation
public void setMessage(String message){
this.message = message;
}
//called by ztemplates after url is matched and variables are assigned
//do the work here
public void after() throws Exception {
HelloWorldView view = new HelloWorldView(message);
ZTemplates.getServletService().render(view);
}
}
|
Next steps
updated for version 0.9.9.6