Summary and Further Readings
From Documentation
This article is out of date, please refer to http://books.zkoss.org/zkessentials-book/master/ for more up to date information.
We glimpsed into the fundamental principles behind how ZK works and we employed some of the essential features of ZK to build a sample shopping cart applications in this book. Let's recap on these elements in ZK:
Components
- Components are UI elements that an application developer piece together to build the application UI.
Think LEGO, consult Component Reference guide on what children components a particular component can have. - Components can be declared in ZUML (ZK User Interface Markup Language, in XML syntax), or alternatively, in Java.
- Components (POJO) run on JVM at the server, and they have their counter parts (widgets - JS objects) at the client.
- User activities on widgets are reflected to the components at the server; component updates are reflected back to the widgets at client.
- A Page is a "stage" where components come on and off it to play their parts and fulfill their roles.
- Components are conceptually grouped in ID Spaces; we can call the Component.getFellow() method on one component to get another component as long as they are in the same ID Space.
- By default, components declared in Window form an ID Space (including Window itself) with Window being the ID Space Ownder.
- By default, a Page is an ID Space Owner; any component can become the ID Space Owner by implementing IdSpace
- Components are UI elements that an application developer piece together to build the application UI.
Events
- User activities (eg. onClick) and system notifications (eg. server push) are abstracted to event objects.
- Register event listeners on components so event objects can be created and forwarded.
- By default, all events are send to the server for processing.
- With ZK's Server+client Fusion architecture, events could also be handled at the client directly.
- Event handling code can be declared as a component attribute in ZUL.
- Events can be forwarded to a controller class for handling.
- Event listeners can be added dynamically in Java.
ZK MVC
- Under the ZK MVC pattern, UI components are declared with ZUML in ZUL files and tasks such as setting a component's data model and renderer, component manipulation, are implemented in a Controller class in Java
- The controller class should extend GenericForwardComposer so components declared in ZUL can be referenced in Java code and events are automatically forwarded to the controller class for handling.
Data Display in UI: View-Model-Renderer
- The View-Model-Renderer approach facilitates the display of a data collection in a component such as a Grid or Listbox.
- The Model is a wrapper for a Java Collection which serves as an interface between the ZK framework and the data collection. For example, ListModelList takes a list as its argument and allows the framework to access and manipulate data objects within the collection.
- The Renderer provides a set of instructions for associating a bean and bean's properties to UI components.
Annotated Data Binding
- Annotated Data Binding allows bean properties to be declared as component attribute values so that View and Model are bound automatically without the need to specify a Renderer or creating a Model wrapper explicitly.
- Under the hood, data binder calls a bean's getter and setter methods to retrieve, or set values in UI components.
- Data binding works with ZK MVC as such:
- Controller class provides a getter method to obtain the bean, or Collection.
- Declare the bean, or Collection as the value for a UI component in ZUL, and the data binder will call the Controller class' getter method under the hood.
=