org.zkoss.zk.ui.util
Class GenericAutowireComposer

java.lang.Object
  extended by org.zkoss.zk.ui.event.GenericEventListener
      extended by org.zkoss.zk.ui.util.GenericComposer
          extended by org.zkoss.zk.ui.util.GenericAutowireComposer
All Implemented Interfaces:
java.io.Serializable, EventListener, ComponentActivationListener, ComponentCloneListener, Composer, ComposerExt
Direct Known Subclasses:
GenericForwardComposer

public abstract class GenericAutowireComposer
extends GenericComposer
implements ComponentCloneListener, ComponentActivationListener

An abstract composer that you can extend and write intuitive onXxx event handler methods with "auto-wired" accessible variable objects such as implicit objects, components, and external resolvable variables in a ZK zuml page; this class will registers onXxx events to the supervised component and wire all accessible variable objects to this composer by calling setXxx() method or set xxx field value directly per the variable name. Since 3.0.7, this composer has wired all implicit objects such as self, spaceOwner, page, desktop, session, application, componentScope, spaceScope, pageScope, desktopScope, sessionScope, applicationScope, and requestScope, so you can use them directly. Besides that, it also provides alert(String message) method, so you can call alert() without problems.

Notice that since this composer kept references to the components, single instance composer object cannot be shared by multiple components.

The following is an example. The onOK event listener is registered into the target window, and the Textbox component with id name "mytextbox" is injected into the "mytextbox" field automatically (so you can use mytextbox variable directly in onOK).


 MyComposer.java
 
 public class MyComposer extends GenericAutowireComposer {
     private Textbox mytextbox;
     
     public void onOK() {
         mytextbox.setValue("Enter Pressed");
         alert("Hi!");
     }
 }
 
 test.zul
 
 <window id="mywin" apply="MyComposer">
     <textbox id="mytextbox"/>
 </window>
 

Since:
3.0.6
Author:
henrichen
See Also:
Components.wireFellows(org.zkoss.zk.ui.IdSpace, java.lang.Object), Serialized Form

Field Summary
protected  char _separator
          The separator.
protected  WebApp application
          Implicit Object; the web application.
protected  java.util.Map applicationScope
          Implicit Object; a map of attributes defined in the web application.
protected  java.util.Map arg
          Implicit Object; the arg argument passed to the createComponents method.
protected  java.util.Map componentScope
          Implicit Object; a map of attributes defined in the applied component.
protected  Desktop desktop
          Implicit Object; the desktop.
protected  java.util.Map desktopScope
          Implicit Object; a map of attributes defined in the desktop.
protected  Execution execution
          Implicit Object; the current execution.
protected  Page page
          Implicit Object; the page.
protected  java.util.Map pageScope
          Implicit Object; a map of attributes defined in the page.
protected  java.util.Map param
          Implicit Object; the param argument passed from the http request.
protected  java.util.Map requestScope
          Implicit Object; a map of attributes defined in the request.
protected  Component self
          Implicit Object; the applied component itself.
protected  Session session
          Implicit Object; the session.
protected  java.util.Map sessionScope
          Implicit Object; a map of attributes defined in the session.
protected  IdSpace spaceOwner
          Implicit Object; the space owner of the applied component.
protected  java.util.Map spaceScope
          Implicit Object; a map of attributes defined in the ID space contains the applied component.
 
Fields inherited from class org.zkoss.zk.ui.util.GenericComposer
_applied
 
Constructor Summary
protected GenericAutowireComposer()
           
protected GenericAutowireComposer(char separator)
          Constructor with a custom separator.
 
Method Summary
protected  void alert(java.lang.String m)
           
 void didActivate(Component comp)
          Called when a session has just been activated (and its value has been deserialized).
 void doAfterCompose(Component comp)
          Auto wire accessible variables of the specified component into a controller Java object; a subclass that override this method should remember to call super.doAfterCompose(comp) or it will not work.
 java.lang.Object willClone(Component comp)
          Internal use only.
 
Methods inherited from class org.zkoss.zk.ui.util.GenericComposer
doBeforeCompose, doBeforeComposeChildren, doCatch, doFinally, willPassivate
 
Methods inherited from class org.zkoss.zk.ui.event.GenericEventListener
bindComponent, getController, onEvent, unbindComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.zkoss.zk.ui.util.ComponentActivationListener
willPassivate
 

Field Detail

self

protected transient Component self
Implicit Object; the applied component itself.

Since:
3.0.7

spaceOwner

protected transient IdSpace spaceOwner
Implicit Object; the space owner of the applied component.

Since:
3.0.7

page

protected transient Page page
Implicit Object; the page.

Since:
3.0.7

desktop

protected transient Desktop desktop
Implicit Object; the desktop.

Since:
3.0.7

session

protected transient Session session
Implicit Object; the session.

Since:
3.0.7

application

protected transient WebApp application
Implicit Object; the web application.

Since:
3.0.7

componentScope

protected transient java.util.Map componentScope
Implicit Object; a map of attributes defined in the applied component.

Since:
3.0.7

spaceScope

protected transient java.util.Map spaceScope
Implicit Object; a map of attributes defined in the ID space contains the applied component.

Since:
3.0.7

pageScope

protected transient java.util.Map pageScope
Implicit Object; a map of attributes defined in the page.

Since:
3.0.7

desktopScope

protected transient java.util.Map desktopScope
Implicit Object; a map of attributes defined in the desktop.

Since:
3.0.7

sessionScope

protected transient java.util.Map sessionScope
Implicit Object; a map of attributes defined in the session.

Since:
3.0.7

applicationScope

protected transient java.util.Map applicationScope
Implicit Object; a map of attributes defined in the web application.

Since:
3.0.7

requestScope

protected transient java.util.Map requestScope
Implicit Object; a map of attributes defined in the request.

Since:
3.0.7

execution

protected transient Execution execution
Implicit Object; the current execution.

Since:
3.0.7

arg

protected transient java.util.Map arg
Implicit Object; the arg argument passed to the createComponents method. It is never null.

Since:
3.0.8

param

protected transient java.util.Map param
Implicit Object; the param argument passed from the http request.

Since:
3.6.1

_separator

protected final char _separator
The separator.

Constructor Detail

GenericAutowireComposer

protected GenericAutowireComposer()

GenericAutowireComposer

protected GenericAutowireComposer(char separator)
Constructor with a custom separator. The separator is used to separate the component ID and event name. By default, it is '$'. For Grooy and other environment that '$' is not applicable, you can specify '_'.

Since:
3.6.0
Method Detail

doAfterCompose

public void doAfterCompose(Component comp)
                    throws java.lang.Exception
Auto wire accessible variables of the specified component into a controller Java object; a subclass that override this method should remember to call super.doAfterCompose(comp) or it will not work.

Specified by:
doAfterCompose in interface Composer
Overrides:
doAfterCompose in class GenericComposer
Parameters:
comp - the component has been composed
Throws:
java.lang.Exception

alert

protected void alert(java.lang.String m)

willClone

public java.lang.Object willClone(Component comp)
Internal use only. Call-back method of CloneComposerListener. You shall not call this method directly. Clone this Composer when its applied component is cloned.

Specified by:
willClone in interface ComponentCloneListener
Parameters:
comp - the clone of the applied component
Returns:
A clone of this Composer.
Since:
3.5.2

didActivate

public void didActivate(Component comp)
Description copied from interface: ComponentActivationListener
Called when a session has just been activated (and its value has been deserialized).

Specified by:
didActivate in interface ComponentActivationListener
Overrides:
didActivate in class GenericComposer


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo