updated to version 2.1.0


Is the ztemplates-module responsible for creating the output of your application. This is done by transforming (rendering) a render-pojo to a String. The rendering is done by a ZRenderEngine.

How to use#

Define a render-pojo#

Is a annotated Java class. The @ZRenderer annotation specifies the Renderer class to use. Return values from Java Bean getters anotated with @ZExpose will get exposed to the renderer instance under the name of the Java Beans property.

If annotated with @ZExpose(render=true), the getter return value will automatically be rendered itself by the framework and the resulting String will be exposed to the Renderer. The Renderer sees only the pojo class (to get its annotations) and the exposed values as a Map<String, Object>.


package org.ztemplates.homepage.render.helloworld.velocity;

import org.ztemplates.renderer.ZExpose;
import org.ztemplates.renderer.ZRenderer;
import org.ztemplates.renderer.velocity.ZVelocityRenderer;

public class HelloWorldVelocity
   * This one gets exposed to the context as
   * a property called message, because it is
   * annotated with ZExpose
  public final String message = "Hello World!";

Define a template#

Create HelloWorldVelocity.vm in the same directory as HelloWorldVelocity.java

From Velocity template:

<h1 class="mystyle">${message}</h1>


Define a stylesheet#

It's recommended to put the styling in a css stylesheet.

Create a file HelloWorldVelocity.css in the same directory as HelloWorldVelocity.java

  .mystyle {
     font-style: italic;

Access the style as ztemplates.css. All css styles found in the classpath corresponding to classes annotated with @ZRenderer are aggregated into one stylesheet: ztemplates.css

   <link rel="stylesheet" type="text/css" href="ztemplates.css">


To avoid name collisions, since you can use ${cssId} in the stylename. This is replaced at runtime with a unique identifier, so the style does not collide with styles from other css-fragments.

  .${cssId}-mystyle {
     font-style: italic;

   <link rel="stylesheet" type="text/css" href="ztemplates.css">
From Velocity template:

<h1 class="${cssId}-mystyle">${message}</h1>


Use it#

render to String

String s = ZTemplates.getRenderService().render(pojo);

or render to http-response


or render to template, from the template


See Render Pojo for more details.

Neuen Anhang hinzuf�gen

Du bist nicht autorisiert, Anh�nge zu dieser Seite hochzuladen.
« Diese Seite (Version-) wurde zuletzt am 22-Dez-2013 13:18 von gerdziegler.de ge�ndert.