Urls are the skeleton of a ztemplates application. They are used to trigger callbacks on the active part of a ztemplates webapp, the action-pojos.

Urls are specified by the @ZMatch annotation on the action-pojos. ztemplates computes a matching tree from all ZMatch annotations it finds in the classpath. The tree is shown in the application-server console at startup.

Url format#

The url is a character string separated by '/'. A url must start with '/', except for nested urls. If it ends with '/' the trailing '/' will be ignored.

A url can contain

  • zero or many url-variables in the format ${javaBeanPropertyName}. There must be a JavaBeans property with that name on the action-pojo. As of this version the type of this property must be String, Enum, int, long or ZProperty. The pojo must define a field or setter and getter for the property. If it is ZProperty, the pojo must define only a getter or field, as the class ZProperty has methods to set and get the url-variable. See this tutorial for code example. The url variable can not match any '/' character.
  • zero or many url-references in the format #{javaBeanPropertyName}. There must be a JavaBeans property with that name on the action-pojo. The type of that property must be either a class that is annotated with @ZMatch or a interface. If it is a interface, the classpath must contain one ore many classes that implement that interface and are annotated with ZMatch. There is no explicit OR construct. OR functionality is implemented implicit by url-references and interfaces. A url-reference with interfaces is equivalent to a OR in the matching expression. You have to be careful to make the @ZMatch annotations on the classes implementing the same interface distinguishable, so the framework can decide which class to instantiate. See this tutorial for code example.
  • zero or many optional expressions in the format [optionalExpression]. Optional expressions can be nested.
  • zero or one *{var} tail-expression at the end of the expression. This will match everything to the end of the url, even '/' that cannot be otherwise matched by a url variable. The value will not be decoded. Use this to create resource loaders, where the end part of the url references the resource to be loaded.

Url parameters#

Url parameters are assigned to the pojo that declares them in the @ZMatch annotation before the after() callback is called.

The setter can accept either a String or a String array. You can use ZProperty for parameters as well.


See form action pojos for how parameters are used with forms.

Url creation#

Urls can be created

  • by hand - write your url down as you always did
  • by framework - in a refactoring-safe way using a ZIUrlFactory
 //fill in all url-variables and url-references
 Object actionPojo = ...; 
 ZIUrlFactory urlFactory = new ZUrlFactory(...);
 String url = urlFactory .createUrl(actionPojo);
  • by framework in webapp - use the ActionService which prepends the contextPath to the url
 //fill in all url-variables and url-references
 Object actionPojo = ...; 
 String url = ZTemplates.getActionService().createUrl(actionPojo);

Url examples#

url components matches
/index none /index
/books/id-${bookId} url-variable bookId /books/id-1 and /books/id-12345bla
/blog/${userId}/${date} url-variables userId and date /blog/Tom_Jones/1.1.2000
/blog/${userId}[/${date}] url-variable userId and optional url-variable date /blog/Tom_Jones/1.1.2000 and /blog/Tom_Jones
/page/#{content} url-reference content /page/bookshelf/show if the action-pojo defined by the 'content' bean-property matches 'bookshelf/show'

Url matching#

  1. split the url by the special character '/'
  2. search the match tree nodes for a node that matches the expression. You can see the match tree in the console of your application server at first request. The tree is processed top down, more specific first.
  3. Then instantiate the corresponding action-pojo and begin the url processing.

urls in ztemplates-web#

In ztemplates-web urls are processed by the ZServletFilter. There is a tutorial on how to setup a ztemplates webapp.

The url computed from the HttpServletRequest always starts with a '/'. There are no trailing '/'.

Neuen Anhang hinzuf�gen

Du bist nicht autorisiert, Anh�nge zu dieser Seite hochzuladen.
« Diese Seite (Version-) wurde zuletzt am 29-Dez-2011 11:24 von gerdziegler.de ge�ndert.