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 more about ZK.
They serve different purposes and could work together. However, some developers get confused about these technologies.
When to use MVC and/or MVVM
MVC (Model-View-Control; aka., Model-View-Presenter) and MVVM (Model-View-ViewModel; aka., Presentation Model) are both design patterns that isolate the dependency among the domain data, the domain logic and the user interface. They are both supported by ZK, and they are praised for its separation of concerns and thus easy to collaborate, develop and maintain. For a production system, it is strongly suggested to take either MVC or MVVM approach.
MVC separates the design into three roles: model, view and controller. The controller is the middle-man gluing the view and the model (aka., data).
On the other hand, MVVM has three roles: View, Model and ViewModel. The View and Model plays the same roles as they do in MVC. The ViewModel in MVVM acts like a special controller. Unlike MVC, ViewModel introduces additional abstraction, so it can be written without any detailed knowledge of the view. In other words, the change of the view will have much less impact to the ViewModel. However, the extra abstraction requires extra design thinking.
In most cases, MVVM is suggested for better separation of concerns. On the other hand, MVC is good for small user interface, such as implementing a macro or composite component, because it is quite straightforward.
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 interpreter, 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.
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 programmers' productivity and the code is easy to read and maintain.
When not to use
Barely. However, as Data Binding requires more time and effort to learn than EL expressions, EL expressions provides an alternative for people who not familiar with ZK, especially during the UI design phase.
When to use ZUML
ZUML is an XML-based approach to declare UI. It does not require any programming knowledge and it 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 the 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 a 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 would like to use ZK in legacy JSP pages, you could try one of following approaches:
<jsp:include>in a ZUML page.
- Apply ZK JSP Tags to a JSP page directly.
As described above, if most of a page consist pure HTML code and the UI designer is not familiar with ZUML, you could use JSP to design the page and then include it in ZUML pages if necessarily.
Notice that ZUML supports the use of HTML tags well (without JSP). For more information, please refer to the ZK Developer's Reference: HTML Tags.
Bookmarks vs. Multiple Pages
A traditional page-based Web framework forces developers to 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 experience.
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 want to group it into a single page.
- If SEO (i.e., able to be indexed by search engine) is important, it is better to split UI into multiple pages (and turn on the crawlable option).
It does not matter whether the UI shares the same template (such as header and footer) or not because it will be easy anyway to create similar multiple pages (by the use of inclusion, templating and composite).
When to use bookmarks (in single page)
After grouping a set of functionality into a single page, users can still click on the BACK and the 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.
ZK provides several ways to use XHTML tags in a ZUML document. Here we will discuss native namespace vs. XHTML components. In a ZUML document, they basically mean the same thing except for the XML namespace. Therefore it should be 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 they are 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 will not be able to change the content dynamically with Ajax. The header, sidebar, footer and the 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.
- ZK Developer's Reference: HTML Tags
- ZK Developer's Reference: Performance Tips|Native vs. XHTML
- ZK Developer's Reference: Performance Tips: Stubonly
Include, Macro, Composite and Templating
They allow developers to modularize the UI such that it becomes 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. This is the most suitable for usage if you would like to:
The limitation of Include is that you can not encapsulate its behavior in a Java class (like macro or composite components do).
- You have to specify
mode="defer"to create a Page instance.
- 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. So if you would like to reuse a ZUML page across different pages, you can use it because
- Though optional, you could encapsulate the behavior in a Java class
- It is easier to map a macro component to another URI, if necessary
- 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. With this approach, you could extend a new component from any existent components. However, you must implement a Java class to represent the component. Unlike macro components, you have to handle the component creation from a ZUML page by yourself.
- Here is an example of composite components in ZK Demo
- There is a utility called ZK Composite. It allows to define a composite component with Java annotations. Please refer to Small Talks: Define Composite Component using Java Annotation in ZK6 for the details.
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 would like the overall layout to be decided at runtime based on, let's say, users' roles or preferences.
Performance and Security
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.
- Notice that ZK JSF Components is no longer supported.