Specify Stubonly for Client-only Components"

From Documentation
Line 47: Line 47:
  
 
== Event Handling ==
 
== Event Handling ==
 +
 +
ZK will preserve all registered event listeners and handlers, when converting a stub-only component to a stub component. In other words, the listener will be called if the corresponding event is fired. However, since the original component no longer exists, the event is fired in the most generic format: an instance of <javadoc>org.zkoss.zk.ui.event.Event</javadoc>, rather than a derived class.
 +
 +
For example, in the following snippet, "org.zkoss.zk.ui.event.Event:onChange" will be generated to <tt>System.out</tt>.
 +
 +
<source lang="xml">
 +
<textbox stubonly="true" onChange='System.out.println(event.getClass().getName()+":"+event.getName())'/>
 +
</source>
 +
 +
In addition, the target (<javadoc method="getTarget()">org.zkoss.zk.ui.event.Event</javadoc>) is the stub component rather than the original one (<tt>text</tt>).
  
 
== Client-side Programming ==
 
== Client-side Programming ==

Revision as of 11:02, 9 August 2010

DocumentationZK Developer's ReferencePerformance TipsSpecify Stubonly for Client-only Components
Specify Stubonly for Client-only Components


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Overview

[since 5.0.4][ZK EE]

It is common that the states of some components are not required to maintain at the server. A typical example is that an application might use some components, such as hbox, for layout and won't access it again after rendered. To minimize the memory footprint, ZK supports a special property called stubonly (Component.setStubonly(String)). Once specified with true, its states won't be maintained at the server (and all states are maintained at the client). For example,

<hbox stubonly="true">
</hbox>

Values of Stubonly: true, false and inherit

The default value of the stubonly property is inherit. It means the value is the same as its parent's, if any, or false, if no parent at all. Thus, if a component's stubonly is specified with true, all its descendants are stub-only too, unless false is specified explicitly. For example, in the following snippet, only textbox is not stub-only, while hbox, splitter, listbox, listitem and labels are all stub-only.

<hbox stubonly="true">
  a stub-only label
  <textbox stubonly="false"/>
  <splitter/>
  <listbox>
    <listitem label="also stubonly"/>
  </listbox>
</hbox>

Limitation of Stub Components

When a component is stub only, it will be replaced with a special component called a stub component (StubComponent) after rendered. In additions, adjacent stub components might be merged to minimize the memory further. Thus, the application shall not access the component again at the server, if it is specified as stub only.

Invalidation

While a stub component cannot be invalidated directly, it is safe to invalidate its parent. ZK will rerender all non-stub components and retain the states of stub components at the client. For example, in the following snippet, it is safe to click the invalidate button. For end user's point of view, there is no difference whether stubonly is specified or not.

 <window>
  <button label="self.parent.invalidate()"/>
  <vbox stubonly="true">
  stubonly <textbox/>
  </vbox>
</window>

Event Handling

ZK will preserve all registered event listeners and handlers, when converting a stub-only component to a stub component. In other words, the listener will be called if the corresponding event is fired. However, since the original component no longer exists, the event is fired in the most generic format: an instance of Event, rather than a derived class.

For example, in the following snippet, "org.zkoss.zk.ui.event.Event:onChange" will be generated to System.out.

<textbox stubonly="true" onChange='System.out.println(event.getClass().getName()+":"+event.getName())'/>

In addition, the target (Event.getTarget()) is the stub component rather than the original one (text).

Client-side Programming


Last Update : 2010/08/09

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


link title