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.
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
Url parameters are assigned to the pojo that declares them in the @ZMatch annotation before the after() callback is called. Parameters are consumed, that means they are assigned only once, and because they are assigned before the after() callback the deepest nested action-pojo will get the parameter. Parameters are consumed depth-first. As of version 0.9.8 there are no callbacks on parameters.
The setter can accept either a String or a String array. You can use ZProperty for parameters as well.
forms parameter names with '.' are not supported anymore starting from version 0.9.9.7
You can also define a form for parameters.
@ZMatch(value = "/", parameters = {"myform.prop1"})
Define a property myform in your action-pojo, define a property prop1 in your form object. To avoid deep links into your object structure only one nesting level is allowed, myform.form.prop1 won't work. This feature was introduced to allow the definition of a form object that can be shared between action-pojo and render-pojo. (not supported anymore)
since 0.9.9.7 use the ZMatch(form="formName") feature to declare a form object.
Urls can be created
//fill in all url-variables and url-references Object actionPojo = ...; ZIUrlFactory urlFactory = new ZUrlFactory(...); String url = urlFactory .createUrl(actionPojo);
//fill in all url-variables and url-references Object actionPojo = ...; String url = ZTemplates.getServletService().createUrl(actionPojo);
| 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' |
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 '/'.