ZK 6: Upgrade Notes"

From Documentation
Line 8: Line 8:
 
In additions to new features, ZK 6 also cleans up some API that are confusing, redundant or over complicated. The effort to upgrade depends on what features your application uses. Many of them shall run without modification. It is suggested to re-compile the applications and replace the code that use the deprecated API.
 
In additions to new features, ZK 6 also cleans up some API that are confusing, redundant or over complicated. The effort to upgrade depends on what features your application uses. Many of them shall run without modification. It is suggested to re-compile the applications and replace the code that use the deprecated API.
  
=Upgrade addons =
+
=The must-do upgrade steps =
Here is a list of addons that you have to upgrade:
+
 
 +
First, you have to upgrade the following addons if you ever use them:
  
 
* ZK JSP 2.0 or later. [http://code.google.com/p/zkjsp/downloads/list Download here].
 
* ZK JSP 2.0 or later. [http://code.google.com/p/zkjsp/downloads/list Download here].
 
* ZK Calendar 2.1.1 or later. [http://code.google.com/p/zkcalendar/downloads/list Download here].
 
* ZK Calendar 2.1.1 or later. [http://code.google.com/p/zkcalendar/downloads/list Download here].
  
In additions, <tt>zcommons-el.jar</tt> is replaced with <tt>zel.jar</tt> supporting EL 2.2. If you prefer EL 1.1 (i.e., backward compatible with ZK 5), please remove <tt>zel.jar</tt> and copy <tt>zcommons-el.jar</tt> to your project instead<ref>ZK Bind (our new generation of data binding) utilizes EL 2.2 to support two-way binding, so don't use <tt>zcommons-el.jar</tt> if you want to use the new data binding.</ref>.
+
Second, you have to remove <code>breeze.jar</code> since [[#Breeze is the default theme|breeze has become the standard theme]]. Without removing the old <code>breeze.jar</code>, it might cause some CSS conflicts.
 +
 
 +
Third, search if you implemented renderer in zscript, such as <javadoc type="interface">org.zkoss.zul.ListitemRender</javadoc>, <javadoc type="interface">org.zkoss.zul.RowRender</javadoc> and <javadoc type="interface">org.zkoss.zul.TreeitemRender</javadoc><ref>If you implement them in pure Java, the compiler will identify the errors for you.</ref>. If so, please refer to [[#The_render_method_of_ListitemRender.2C_RowRender.2C_TreeitemRender_and_ComboitemRender_are_changed|this section]] for details.
 +
 
 +
Fourth, clean and compile your project. If there is an error, please check the corresponding section below.
  
Furthermore, you have to remove <code>breeze.jar</code> since [[#Breeze is the default theme|breeze has become the standard theme]]. Without removing the old <code>breeze.jar</code>, it might cause some conflicts.
+
Finally, <tt>zcommons-el.jar</tt> is replaced with <tt>zel.jar</tt> supporting EL 2.2<ref>If you prefer EL 1.1 (i.e., backward compatible with ZK 5), please remove <tt>zel.jar</tt> and copy <tt>zcommons-el.jar</tt> to your project instead. Notice that ZK Bind (our new generation of data binding) utilizes EL 2.2 to support two-way binding, so don't use <tt>zcommons-el.jar</tt> if you want to use the new data binding.</ref>. Though optional, it is suggested to remove <code>zcommons-el.jar</code>.
  
 
<blockquote>
 
<blockquote>

Revision as of 03:33, 14 February 2012

ZK 6: Upgrade Notes

Author
ZK Team, Potix Corporation
Date
February 14, 2012
Version
ZK 6

Overview

In additions to new features, ZK 6 also cleans up some API that are confusing, redundant or over complicated. The effort to upgrade depends on what features your application uses. Many of them shall run without modification. It is suggested to re-compile the applications and replace the code that use the deprecated API.

The must-do upgrade steps

First, you have to upgrade the following addons if you ever use them:

Second, you have to remove breeze.jar since breeze has become the standard theme. Without removing the old breeze.jar, it might cause some CSS conflicts.

Third, search if you implemented renderer in zscript, such as ListitemRender, RowRender and TreeitemRender[1]. If so, please refer to this section for details.

Fourth, clean and compile your project. If there is an error, please check the corresponding section below.

Finally, zcommons-el.jar is replaced with zel.jar supporting EL 2.2[2]. Though optional, it is suggested to remove zcommons-el.jar.


  1. If you implement them in pure Java, the compiler will identify the errors for you.
  2. If you prefer EL 1.1 (i.e., backward compatible with ZK 5), please remove zel.jar and copy zcommons-el.jar to your project instead. Notice that ZK Bind (our new generation of data binding) utilizes EL 2.2 to support two-way binding, so don't use zcommons-el.jar if you want to use the new data binding.

API that are changed

org.zkoss.zk.zul.api.* are removed

The component's API interfaces (org.zkoss.zk.ui.api.*, org.zkoss.zul.api.*...) are removed[1]. Please replace them with the concrete classes. For example, use org.zkoss.zul.Window instead of org.zkoss.zul.api.Window.

You could use the search-and-replace or refactor feature in your IDE to replace the package name. Here is an example that uses Eclipse to replace the package name.


  1. The reason to remove them is they cause more confusion than the abstraction benefit. In additions, they are costly and error-prone to maintain.

The render method of ListitemRender, RowRender, TreeitemRender and ComboitemRender are changed

For sake of performance and consistency, the render method of ListitemRender, RowRender, ComboitemRender, TreeitemRender are changed. An addition argument called index was introduced. You can use it instead of accessing the component's index (such as Listitem.getIndex() for better performance.

Notice that, while Java compiler will detect the changes, you have to maintain zscript manually if you ever implemented them in zscript.

org.zkoss.zk.ui.util.Initiator is simplified

For easy extension and better consistency[1], the Initiator class now has only one method called doInit. The doAfterComposer, doCatch and doFinally methods are moved to InitiatorExt. In other words, if you'd like to override any of these methods, your initiator has to implement both Initiator and InitiatorExt.


  1. Most initiators need to override the doInit method, and it is consistent with Composer.

org.zkoss.xel.FunctionMapper is simplified

For easy extension[1], the getClassNames and resolveClass methods of the org.zkoss.xel.FunctionMapper class are removed. On the other hand, org.zkoss.xel.FunctionMapperExt was introduced to have these methods. In other words, you'd like to implement any of these methods, you have to implement both FunctionMapper and FunctionMapperExt.


  1. The getClassNames and resolveClass methods are useful only for special evaluators, such as MVEL and OGNL

i3-label.properties is renamed to zk-label.properties

To avoid confusion, the default properties file for the internationalization labels is renamed to zk-label.properties[1].


  1. For backward compatibility, i3-label.properties will be loaded if zk-label.properties is not found.

The selection and opened objects are maintained in model, not UI

The selection and opened objects are maintained in model, such as ListModel and TreeModel. The application shall access the model rather than the component. The component (such as Listbox) will reflect the change in the model to UI automatically.

Furthermore, if the application invokes Sortable.sort(Comparator, boolean) of the model, the component will be updated to reflect the result automatically. Of course, it also means your implementation has to fire the data change event correctly.

It is also important to note that the selection and other information in the component might not be complete because of render-on-demand. For example, if the first and the last item are both selected, then Listbox.getSelectedItems() might return only the first item, since the last item is not loaded and rendered (for sake of better performance). Thus, the application shall access the model where all data are available.

The selection and open contract between Tree and TreeModel become TreeSelectableModel and TreeOpenableModel

For better performance, TreeSelectableModel and TreeOpenableModel are introduced to replace Selectable and Openable for maintaining the selection and open objects. In short, they depend on the tree path rather than the data objects.

For backward compatibility, AbstractTreeModel also implements Selectable and Openable. Application is free to access it, though ZK doesn't count on them. However, since their contract is based the data objects, TreeModel.getPath(E) will be called to get the tree path. Thus, make sure your implementation is good if you invoke them a lot.

SimpleTreeModel and SimpleTreeNode are removed

The org.zkoss.zul.SimpleTreeModel and org.zkoss.zul.SimpleTreeNode classes are removed[1], and replaced with DefaultTreeModel and DefaultTreeNode.


  1. It was deprecated in ZK 5.0.6.

The isClose and setClose methods of GroupsModel are deprecated

To be consistent with the naming of other models, these two methods are replaced with GroupsModel.isGroupOpen(), GroupsModel.addOpenGroup(int) and GroupsModel.removeOpenGroup(int).

GenericForwardComposer and GenericAutowireComposer won't wire variables defined in zscript and variable resolvers

For sake of better performance, org.zkoss.zk.ui.util.GenericForwardComposer and org.zkoss.zk.ui.util.GenericAutowireComposer won't wire variables defined in zscript and variable resolvers. If you prefer to write them as ZK 5 and earlier does, you could specify the library properties called org.zkoss.zk.ui.composer.autowire.zscript and org.zkoss.zk.ui.composer.autowire.xel to true.

API returns Iterable instead Iterator

To use with Java 5's for statement, the return type of the following APIs are changed to java.lang.Iterable:

  • org.zkoss.zk.ui.Exectuion: getHeaders and getHeaderNames
  • org.zkoss.zk.ui.WebApp: getInitParameterNames
  • org.zkoss.zk.ui.RichletConfig: getInitParameterNames

Window, Messagebox and Fileupload won't throw InterruptedException

Window, Messagebox and Fileupload won't throw java.lang.InterruptedException anymore, since it won't happen if the event processing thread is disabled (default). If the event processing thread is enabled, InterruptedException will be wrapped with UiException.

addEventListener allows the same listener registered multiple times

Component's addEventListener now allows the same listener being registered multiple times, and the listener will be called multiple times.

If you prefer to ignore the second registration of the same listener (i.e., backward compatible with ZK 5 and earlier), you could specify a library property called org.zkoss.zk.ui.EventListener.duplicateIgnored to true in WEB-INF/zk.xml.

The return type of Annotation.getAttributes() is changed

The return type is changed from Map<String, String> to Map<String, String[]>, since the annotation now allows multiple values per attribute.

UiFactory's newComponent is changed

The newComponent method of the org.zkoss.zk.ui.sys.UiFactory is changed. In additions, two new methods newComposer and newServerPush were introduced to allow developers have more control of the instantiations.

The support of Comet is available in PE

The support of Comet is available in ZK PE, while ZK EE supports Servlet 3 Asynchronous Processing-based Comet.

Component's newChildren and newExtraCtrl are removed

The newChildren and newExtraCtrl methods of AbstractComponent are removed since they are redundant. Please override the getChildren and getExtraCtrl instead.

Component's setVariable is removed

Component's setVariable method is removed[1]. Please use Component.setAttribute(name, value, SPACE_SCOPE) instead. In other words, you could store the variables in the attributes of the space owner (Component.getSpaceOwner()).


  1. It was deprecated in ZK 5, since we don't maintain a separate namespace for each ID space.

ListX, TreeArray and CheckableTreeArray are removed

The org.zkoss.util.ListX, org.zkoss.util.TreeArray and org.zkoss.util.CheckableTreeArray are removed. Please use java.util.LinkedList or java.util.ArrayList instead.

ClassWebServlet and several other never-used classes are removed

The following classes are removed, since they are never used and introduce unnecessary complication to API:

org.zkoss.web.util.resource.ClassWebServlet, org.zkoss.web.servlet.ForwardServlet, org.zkoss.web.servlet.http.HttpServlet, org.zkoss.io.PrintWriterX, org.zkoss.io.FileWatchdog, org.zkoss.media.Photo, org.zkoss.lang.WarningException, org.zkoss.lang.Warning, org.zkoss.util.InvalidValueException, org.zkoss.util.ModificationException, org.zkoss.util.ScalableTimer, org.zkoss.util.ScalableTimerTask, org.zkoss.util.ScalableTimerTask, org.zkoss.util.ThreadLocalCache

If you need them, please copy the code from ZK 5's Git repository.

The configuration of logging is changed

ZK core's logging is still based on Java standard logging. However, the configuration is simplified and changed. Please refer to ZK Developer's Reference: Logger if you need it.

API that are deprecated

ListModelExt, TreeModelExt and GroupsModelExt are deprecated

The org.zkoss.zul.ListModelExt and org.zkoss.zul.TreeModelExt interface are deprecated, and replaced with Sortable. Also, org.zkoss.zul.GroupsModelExt is deprecated and replaced with GroupsSortableModel.

org.zkoss.zk.ui.event.Express is deprecated

The org.zkoss.zk.ui.event.Express interface is deprecated. Please use the addEventListener(int, String, EventListener) method instead, and assign the priority as 1000.

HTMLs, StyleSheet and JavaScript are moved

The HTMLs, StyleSheet and JavaScript classes are moved to the package called org.zkoss.html.

Notice the previous classes are still available but deprecated (not found in JavaDoc).

Theme and UI

Breeze is the default theme

The breeze theme has become the default styling, without the need to include breeze.jar. Please make sure you remove breeze.jar from your project. On the other hand, the sapphire and silvertail themes are packaged and delivered as they were in ZK 5. Of course, you have to upgrade to the version shipped with ZK 6's binary distribution.

Tablechildren and Columnchidlren support any child

Tablechildren and Columnchildren support any kind of child components, not limited to Panel. Thus, if you don't need the feature of Panel, you could remove it from your UI to make the layout structure simpler.

Groupbox's zclass is renamed to z-groupbox

To be consistent, the zclass of Groupbox's default mold is renamed to z-groupbox(it was called z-fieldset in ZK 5). The zclass of the 3d mold is renamed to z-groupbox-3d (it was called z-groupbox).

The z-class names of menuitem, menupopup, menuseparator and panelchlidren are changed

To be consistent with other naming, we rename their z-class name as follows. Please update your CSS file if you ever override them.

  • z-menu-item -> z-menuitem
  • z-menu-popup -> z-menupopup
  • z-menu-separator -> z-menuseparator
  • z-panel-children -> z-panelchildren

Some nested CSS class names of calendar are changed

To avoid confusion with other components, the CSS class names must follow the same rule: z-class-xxxx. We fix calendar to follow this rule. Please update your CSS file if you ever override them.

  • .z-weekend -> .z-calendar-caldow .z-calendar-wkend
  • .z-weekday -> .z-calendar-caldow .z-calendar-wkday
  • .z-outside -> .z-calendar-outside

The vflex and hflex of Panelchildren are deprecated

The hflex/vflex properties of Panelchildren are determined by its parent Panel's hflex/vflex properties. The setHflex and setVflex methods of Panelchildren will throw UnsupportedOperationException. In other words, you shall control Panel rather than Panelchildren.

The hflex and width of Treerow, Rows... is deprecated

As the sizing of Grid/Listbox/Tree are controlled by Grid/Listbox/Tree and the header components (such as Treecol, Listheader and Column). By others, the hflex and width properties of them are irrelevant. Their setHflex and setWidth methods are deprecated. These components include: Treeitem, Treerow, Treecell, Treechildren, Treecols, Treefoot, Rows, Columns, Row, Cell, Foot, Listitem, Listcell, Listhead, Listfoot.

Messagebox's template is changed

Messagebox's template (i.e., ~./zul/html/messagebox.zul) is changed to support the new features such as reordering and custom labels. If you ever customized it, please refer to the source code for the details.

iZUML uses #{...} to represent an expression

The format of the expression used in iZUML (client-side ZUML) has become #{...}, such that it is easier to embed in a ZUML page where ${...} is used. In additions, iZUML is supported by ZK CE since ZK 6.

The library property called org.zkoss.zul.Separator.spaceWithMargin is removed

We don't support the margin approach found in ZK 2 any more.

Optional but suggested

Use ZK Bind instead of old data binding

ZK Bind (org.zkoss.bind.*) is our new generation of data binding. It is more powerful and controllable, though the first version of data binding (org.zkoss.zkplus.databind.*) is still maintained. For more information, please refer to Envisage ZK 6: The Next Generation Data Binding System.

Notice that ZK Bind supports both data binding and MVVM. Data binding, as you are already familiar with, minimizes the effort to access database, while MVVM introduces additional abstract layer isolating the view dependence from the controller.

Use SelectorComposer instead of GenericForwardComposer

The org.zkoss.zk.ui.select.GenericAnnotatedComposer class provides more control how to wire the members. It is generally recommended. Of course, some might find org.zkoss.zk.ui.util.GenericForwardComposer's wire-by-convention is more convenient to use, and it is still supported.


Comments



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