Package org.zkoss.zk.ui.util

## Class GenericForwardComposer<T extends Component>

- java.lang.Object
- - org.zkoss.zk.ui.event.GenericEventListener
  - - org.zkoss.zk.ui.util.GenericComposer<T>
    - - org.zkoss.zk.ui.util.GenericAutowireComposer<T>
      - - org.zkoss.zk.ui.util.GenericForwardComposer<T>

- All Implemented Interfaces:
    `java.io.Serializable`, `EventListener`, `SerializableEventListener`, `ComponentActivationListener`, `ComponentCloneListener`, `Composer<T>`, `ComposerExt<T>`

      public abstract class GenericForwardComposer<T extends Component>
      extends GenericAutowireComposer<T>

  A skeletal composer that you can extend and write intuitive onXxx$myid event handler methods with auto event forwarding and "auto-wired" accessible variable objects such as embedded objects, components, and external resolvable variables in a ZK zuml page; this class will add forward condition to the myid source component and forward source onXxx event received by the source myid component to the target onXxx$myid event (as defined in this composer) of the supervised target component; of course it will also registers onXxx$myid 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.

  Alternatives: in most cases, 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 improperly.

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

  The following is an example. The onChange event received by Textbox mytextbox will be forwarded to target Window mywin as a new target event onChange$mytextbox and the Textbox component with id name "mytextbox" and Label with id name mylabel are injected into the "mytextbox" and "mylabel" fields respectively(so you can use mytextbox and mylabel variable directly in onChange_mytextbox without problem).

       MyComposer.java

       public class MyComposer extends GenericForwardComposer {
           private Textbox mytextbox;
           private Window self; //embedded object, the supervised window "mywin"
           private Page page; //the ZK zuml page
           private Label mylabel;

           public void onChange$mytextbox(Event event) {
               mylabel.setValue("You just entered: "+ mytextbox.getValue());
           }
       }

       test.zul

       <window id="mywin" apply="MyComposer">
           <textbox id="mytextbox"/>
           <label id="mylabel"/>
       </window>

  Since:
    3.0.7
  Author:
    henrichen
  See Also:
    `ConventionWires`, Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.zkoss.zk.ui.util.GenericAutowireComposer

      `_separator, application, applicationScope, arg, componentScope, desktop, desktopScope, execution, page, pageScope, param, requestScope, self, session, sessionScope, spaceOwner, spaceScope`

    - ### Fields inherited from class org.zkoss.zk.ui.util.GenericComposer

      `_applied`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `GenericForwardComposer()` | The default constructor.
    `protected` | `GenericForwardComposer​(char separator)` | Constructor with a custom separator.
    `protected` | `GenericForwardComposer​(char separator, boolean ignoreZScript, boolean ignoreXel)` | Constructor with full control.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `doAfterCompose​(T comp)` | Auto forward events and 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.

    - ### Methods inherited from class org.zkoss.zk.ui.util.GenericAutowireComposer

      `alert, didActivate, getPage, willClone, willPassivate`

    - ### Methods inherited from class org.zkoss.zk.ui.util.GenericComposer

      `doBeforeCompose, doBeforeComposeChildren, doCatch, doFinally`

    - ### 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`

- - ### Constructor Detail

    - #### GenericForwardComposer

          protected GenericForwardComposer()

      The default constructor.

      It is a shortcut of `GenericForwardComposer('$', !"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 `GenericForwardComposer(char,boolean,boolean)` instead.

      ## Version Difference

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

    - #### GenericForwardComposer

          protected GenericForwardComposer​(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 `GenericForwardComposer('$', !"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 `GenericForwardComposer(char,boolean,boolean)` instead.

      ## Version Difference

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

      Since:
        3.6.0

    - #### GenericForwardComposer

          protected GenericForwardComposer​(char separator,
                                           boolean ignoreZScript,
                                           boolean ignoreXel)

      Constructor with full control.
      Parameters:
        `separator` - the separator used to separate the component ID and event name. Refer to `GenericAutowireComposer._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 Detail

    - #### doAfterCompose

          public void doAfterCompose​(T comp)
                              throws java.lang.Exception

      Auto forward events and 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<T extends Component>`
      Overrides:
        `doAfterCompose` in class `GenericAutowireComposer<T extends Component>`
      Parameters:
        `comp` - the component has been composed
      Throws:
        `java.lang.Exception`