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.
ztemplates-render is PASSIVE, view layer. That means it should not contain business logic, only data for display. render-pojos should NOT go to the database, access EJBs or do anything smart. Just VIEW data. Passive data-holders. Data is provided to them from the outside. render-pojos are somehow similar to Swing Models, but on a more coarse level. Normally a render-pojo contains data for many gui-controls.
Nevertheless, it IS possible to use the same pojo for view and actions. Decide for yourself.
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>.
HelloWorldVelocity.java
package org.ztemplates.homepage.render.helloworld.velocity;
|
Create HelloWorldVelocity.vm in the same directory as HelloWorldVelocity.java
<html>
From Velocity template:
<h1 class="mystyle">${message}</h1>
</html>
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
<html> <head> <link rel="stylesheet" type="text/css" href="ztemplates.css"> </head> ...
To avoid name collisions, since 0.9.8.6 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;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="ztemplates.css">
</head>
<body>
From Velocity template:
<h1 class="${cssId}-mystyle">${message}</h1>
</body>
</html>
render to String
String s = ZTemplates.getRenderService().render(pojo);
|
or render to http-response
ZTemplates.getServletService().render(pojo);
|
or render to template, from the template
${renderService}.render(${pojo})