Technology Guidelines

From Documentation


Technology Guidelines


ZK provides end-to-end solutions from UI design, development, testing to production. Here is the technology guidelines to help developers to make choices along the way.

If you are new to ZK and prefer to have some prior knowledge of ZK first, you could skip this section and come back later when you understand ZK more.

MVC vs. ZScript

They serve different purposes and could work together. However, some developers get confused about these two technologies.

When to use MVC

MVC (Model-View-Control) is an architectural pattern that isolates the modeling of the domain and the actions on user input are divided into three separate classes: model, view and controller. MVC should be easy to collaborate, develop and maintain. It is praised for its great performance since actions on user input are done in compiled Java code. MVC is said to be the best practice when developing applications, especially for production systems.

When to use zscript

Zscript allows you to embed Java code in ZUML pages. It speeds up the design cycle, so this can be a good approach for prototyping, POC and testing. Zscript is also good for exploiting ZK features and reporting bugs to ZK. However, like any other interpreters, the performance is not very good as it tends to be error-prone. For this reason, it is not suggested to use zscript for production systems.

MVC Extractor

ZK Studio provides a tool called MVC Extractor that can convert zscript into MVC automatically. It simplifies the process of transferring the code from prototyping to production.

Documentation links

MVC:
ZSCRIPT:

Data Binding

When to use

Data Binding automates the data-copy plumbing code (CRUD) between UI components and the data source. It is strongly suggested to use Data Binding whenever applicable because it can help boost programmer productivity and the code is easy to read and maintain.

When not to use

Barely. However, as Data Binding requires more knowledge to learn than EL expressions, EL expressions is an alternative for people who not familiar with ZK, especially during the UI design phase.

Notice that there is a limitation: data binding won't be applied components that are created, after the page is initialized and rendered at the client[1].


  1. This limitation will be resolved in the upcoming Data Binding 2.

Documentation links

ZUML vs. Richlet vs. JSP

When to use ZUML

ZUML is an XML-based approach to declare UI. It does not require programming knowledge, and works well with MVC, Data Binding and others. ZUML is strongly suggested for usage unless you have different preferences (such as pure Java and JSP).

However, if most parts of a page are in HTML scripts (such as header and footer) and UI designer is not familiar with ZUML, you could still use JSP to define the page and then include ZUML page(s) for the part that requires ZK components.

Notice that using ZUML does not prevent you from creating components dynamically in Java. In fact, it is a common practice to use ZUML to layout the theme of the Web application, and then use pure Java to manipulate it dynamically.

When to use Richlet

A richlet is a small Java program that composes a user interface in Java for serving a user's request. You could try to use it if you prefer to compose UI in pure Java (like Swing).

When to use JSP

If you'd like to use ZK in legacy JSP pages, you could use one of following approaches:

  1. Use <jsp:include> to include a ZUML page.
  2. Use ZK JSP Tags in a JSP page directly.

As described above, if most of a page is pure HTML and UI designer is not familiar with ZUML, you could use JSP to design the page, and then include ZUML pages if necessary.

Notice that ZUML support the use of HTML tags well (without JSP). For more information, please refer to ZK Developer's Reference: HTML Tags.

Documentation links

ZUML:
Richlet:
JSP:

Bookmarks vs. Multiple Pages

A traditional page-based Web framework forces developers split an application into pages. On the other hand, Ajax (ZK) allows developers to group a set of functionality into a single desktop-like page that enables a more friendly user experiences.

Grouping is much better based on the functionality, unless it is a small application. For example, it might not be a good idea to group administration with, let's say, data entry. Here are some guidelines:

  • If a set of functionality is a logical unit to use and/or to develop, you might group it into a single page.
  • If SEO (i.e., able to be indexed by search engine) is important, it is better to split into multiple pages (and turn on the crawlable option).

Whether UI shares the same template (such as header and footer) or not, it does not matter. It will be easy anyway to make multiple pages to appear similarly (by use inclusion, templating and composite).

When to use bookmarks (in single page)

After grouping a set of functionality into a single page, you could still allow users to use BACK and FORWARD button to switch among the states of the single page and even bookmark on a particular state, as if there are multiple pages. This can be done by using Browser History Management (aka., bookmarks). You might consider this as a technique to simulate multiple pages (for a single page with multiple states).

When to use multiple pages

If a set of functionality is logically independent of one another, you could make them as separated pages. To jump from one page to another, you could use the so-called send-redirect technique.

Documentation links

Bookmarks:
Multiple Pages:

Native Namespace vs. XHTML Components

ZK provides several ways to mix XHTML tags in a ZUML document. Here we will discuss native namespace vs. XHTML components. In a ZUML document, they are the same except the XML namespace, so it is easy to switch between them.

When to use native namespace

With the use of an XML namespace called the native namespace, you could declare any tags in ZUML as long as it is valid to the client (i.e., any HTML tags for a browser). It is suggested to use this technology if the HTML tags are static. For example, you won't able to change the content dynamically with Ajax. The header, sidebar, footer and layout elements are typical examples. It saves the memory on the server.

When to use XHTML components

ZK also provides a set of components to represent each XHTML tag on the server. Unlike the native namespace, these are the 'real' ZK components.

It is suggested that you may change their content dynamically because they behave the same as other ZK components. However, since it is a component, it consumes the server's memory.

Documentation links

Include, Macro, Composite and Templating

They allow developers to modularize the UI such that it is easier to develop, maintain and reuse.

When to use include

Include allows you to include a ZUML page, a static page, a JSP page or the result of a servlet. It is suggested if you'd like to:

  1. Include a non-ZUML page
  2. Use a page (Page) to encapsulate a ZUML page[1][2]

The limitation of Include is that you can not encapsulate its behavior in a Java class (like macro or composite components do).

  1. You have to specify mode="defer" to create a Page instance.
  2. Whether a page is required really depends on developer's preference. Introducing a page is more complicated but logically more loosely-coupled.

When to use macro components

Macro components allow developers to define a new component with a ZUML page. It is suggested if you'd like to reuse a ZUML page across different pages, you can because

  1. Though optional, you could encapsulate the behavior in a Java class
  2. It is easier to map a macro component to another URI, if necessary
  3. There is no difference between the use of a macro component and other components

When to use composite components

Composite component is another way to define a new component[1]. With this approach, you could extend a new component from any existent component. However, you must implement a Java class to represent the component[2]. Unlike macro components, you have to handle the component creation from a ZUML page by yourself[3].

Feel free to use composite components if you want to inherit the behavior from an existent component, such as Window and Cell, and enhance it to have child components defined in a ZUML document.


  1. It is more a particular pattern of extending an existent component than a technology.
  2. Here is an example of composite components in ZK Demo
  3. It could be done easily with Executions.createComponents(String, Component, Map)

When to use templating

Templating allows developers to define UI fragments, and define how to assemble them into a complete UI at runtime. Its use is very different from other approaches. Feel free to use templating if you'd like the overall layout to be decided at runtime based on, let's say, users' roles or preferences.

Performance and Security

For production systems, it is strongly recommended to take a look at Performance Tips and Security Tips first.

JSF

When to use

JSF is a page-based framework. Because it is too complicated to use, we strongly recommend you to deploy ZK. ZK can do whatever JSF can do or even better. However, if you have to use ZK with legacy JSF, please refer to the Embed ZK Component in Foreign Framework section[1].


  1. Notice that ZK JSF Components is no longer supported.

Version History

Last Update : 2011/09/15


Version Date Content
     


Last Update : 2011/09/15

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.