Class GenericAutowireComposer<T extends Component>

All Implemented Interfaces:
Serializable, EventListener, SerializableEventListener, ComponentActivationListener, ComponentCloneListener, Composer<T>, ComposerExt<T>
Direct Known Subclasses:
GenericForwardComposer

public abstract class GenericAutowireComposer<T extends Component> extends GenericComposer<T> implements ComponentCloneListener, ComponentActivationListener

A skeletal 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. Since 3.5.2, the composer itself would be assigned as an attribute of the supervised component per the naming convention of the component id and composer class name or of component id and "composer". e.g. If the component id is "mywin" and the composer class is org.zkoss.MyComposer, then the composer can be referenced by the variable name of "mywin$MyController" or "mywin$composer". Notice that the '$' separator can be changed to other character such as '_' for Groovy or other environment that '$' is not applicable. Simply extends this class and calling GenericAutowireComposer(char separator) constructor with proper separator character.

Alternatives: in most cases, you don't extend from GenericAutowireComposer directly. Rather, you can extend from one of the following skeletons.

SelectorComposer
It supports the autowiring based on Java annotation and a CSS3-based selector. If you don't know which one to use, use SelectorComposer.
GenericForwardComposer
It supports the autowiring based on naming convention. You don't need to specify annotations explicitly, but it is error-prone if it is used properly.

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). The "value" property of "mytextbox" is assigned with composer's getTitle(), i.e. "ZK".


 MyComposer.java

 public class MyComposer extends GenericAutowireComposer {
     private Textbox mytextbox;

     public void onOK() {
         mytextbox.setValue("Enter Pressed");
         alert("Hi!");
     }
     public String getTitle() {
         return "ZK";
     }
 }

 test.zul

 <window id="mywin" apply="MyComposer">
     <textbox id="mytextbox" value="${mywin$composer.title}"/>
 </window>
 

Since 5.0.8, you could name the composer by specify a custom attribute called composerName. For example,


 <window apply="MyComposer">
 <custom-attribute composerName="mc"/>
     <textbox id="mytextbox" value="${mc.title}"/>
 </window>
 
Since:
3.0.6
Author:
henrichen
See Also:
  • Field Details

    • self

      protected transient T extends 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 Map<String,Object> componentScope
      Implicit Object; a map of attributes defined in the applied component.
      Since:
      3.0.7
    • spaceScope

      protected transient Map<String,Object> spaceScope
      Implicit Object; a map of attributes defined in the ID space contains the applied component.
      Since:
      3.0.7
    • pageScope

      protected transient Map<String,Object> pageScope
      Implicit Object; a map of attributes defined in the page.
      Since:
      3.0.7
    • desktopScope

      protected transient Map<String,Object> desktopScope
      Implicit Object; a map of attributes defined in the desktop.
      Since:
      3.0.7
    • sessionScope

      protected transient Map<String,Object> sessionScope
      Implicit Object; a map of attributes defined in the session.
      Since:
      3.0.7
    • applicationScope

      protected transient Map<String,Object> applicationScope
      Implicit Object; a map of attributes defined in the web application.
      Since:
      3.0.7
    • requestScope

      protected transient Map<String,Object> 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 Map<?,?> arg
      Implicit Object; the arg argument passed to the createComponents method. It is never null.
      Since:
      3.0.8
    • param

      protected transient Map<String,String[]> param
      Implicit Object; the param argument passed from the http request.
      Since:
      3.6.1
    • _separator

      protected char _separator
      The separator used to separate the component ID and event name. By default, it is '$'. For Groovy and other environment that '$' is not applicable, you can specify '_'.
  • Constructor Details

    • GenericAutowireComposer

      protected GenericAutowireComposer()
      The default constructor.

      It is a shortcut of GenericAutowireComposer('$', !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.zscript")), !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.xel"))).

      In other words, whether to ignore variables defined in ZSCRIPT and XEL depends on the library variables called org.zkoss.zk.ui.composer.autowire.zscript and org.zkoss.zk.ui.composer.autowire.xel. Furthermore, if not specified, their values are default to false, i.e., they shall not be wired (i.e., shall be ignored)

      If you want to control whether to wire ZSCRIPT's or XEL's variable explicitly, you could use GenericAutowireComposer(char,boolean,boolean) instead.

      Version Difference

      ZK 5.0 and earlier, this constructor is the same as GenericAutowireComposer('$', false, false)
      In other words, it is default to wire (i.e., shall not ignore).

    • 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 Groovy and other environment that '$' is not applicable, you can specify '_'.

      It is a shortcut of GenericAutowireComposer('$', !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.zscript")), !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.xel"))).

      In other words, whether to ignore variables defined in ZSCRIPT and XEL depends on the library variables called org.zkoss.zk.ui.composer.autowire.zscript and org.zkoss.zk.ui.composer.autowire.xel. Furthermore, if not specified, their values are default to false, i.e., they shall not be wired (i.e., shall be ignored)

      If you want to control whether to wire ZSCRIPT's or XEL's variable explicitly, you could use GenericAutowireComposer(char,boolean,boolean) instead.

      Version Difference

      ZK 5.0 and earlier, this constructor is the same as GenericAutowireComposer('$', false, false)
      In other words, it is default to wire (i.e., shall not ignore).

      Parameters:
      separator - the separator used to separate the component ID and event name. Refer to _separator for details.
      Since:
      3.6.0
    • GenericAutowireComposer

      protected GenericAutowireComposer(char separator, boolean ignoreZScript, boolean ignoreXel)
      Constructors with full control, including separator, whether to search zscript and xel variables
      Parameters:
      separator - the separator used to separate the component ID and event name. Refer to _separator for details.
      ignoreZScript - whether to ignore variables defined in zscript when wiring a member.
      ignoreXel - whether to ignore variables defined in variable resolver (Page.addVariableResolver(org.zkoss.xel.VariableResolver)) when wiring a member.
      Since:
      5.0.3
  • Method Details