logo
Support This Project

News

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.5 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

All files in same location.

View layout

Specify the view layout using your preferred templating technology (Velocity, FreeMarker, JSP...)

HelloWorldView.vm:

<html>
<h1>$message</h1>

$includedView

</html>

View data

/**
* 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;
  }

  //expose 'includedView' to the template 
  //RENDERED as a String
  @ZExpose(render=true
  public AnotherView getIncludedView()  {
    return includedView;
  }
}

Action

/**
* action matches all urls like '/helloworld/*' example: '/helloworld/myText'
*/
@ZMatch("/helloworld/${message}")
public class HelloWorldAction {
  private String message;
  
  //property for matched value 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 {
    //create view pojo
    HelloWorldView view = new HelloWorldView(message)

    //render view to the response
    ZTemplates.getServletService().render(view);
  }
}

Next steps

updated for version 0.9.9.6

  My Prefs Log in
This page (revision-) last changed by gerdziegler.de.
 
(c) 2007 gerdziegler.de
JSPWiki v2.4.69