Interface Composer<T extends Component>

All Known Implementing Classes:
AnnotateDataBindingComposer, BindComposer, GenericAutowireComposer, GenericComposer, GenericForwardComposer, MultiComposer, SelectorComposer

public interface Composer<T extends Component>

Represents a composer to initialize a component (or a component of tree) when ZK loader is composing a component. It is the controller in the MVC pattern, while the component is the view.

To initialize a component, you can implement this interface and then specify the class or an instance of it with the apply attribute as follows.

<window apply="my.MyComposer"/>
<window apply="${a_composer}"/>

Then, ZK loader will

  1. Invoke ComposerExt.doBeforeCompose(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.metainfo.ComponentInfo), if the composer also implements ComposerExt.
  2. Create the component (by use of UiFactory.newComponent(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.metainfo.ComponentInfo, org.zkoss.zk.ui.Component), which creates and initializes the component accordingly).
  3. Invokes ComposerExt.doBeforeComposeChildren(T), if ComposerExt is also implemented.
  4. Composes all children, if any, of this component defined in the ZUML page.
  5. Invokes doAfterCompose(T) after all children are, if any, composed.
  6. Posts the onCreate event if necessary.

To intercept the lifecycle of the creation of a page, implement Initiator and specify the class with the init directive.

Note: AfterCompose has to be implemented as part of a component, while Composer is a controller used to initialize a component (that might or might not implement AfterCompose).

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

It supports the autowiring based on Java annotation and a CSS3-based selector. If you don't know which one to use, use SelectorComposer.
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.

See Also:
AfterCompose, ComposerExt, FullComposer, Initiator

Method Summary
 void doAfterCompose(T comp)
          Invokes after ZK loader creates this component, initializes it and composes all its children, if any.

Method Detail


void doAfterCompose(T comp)
                    throws java.lang.Exception
Invokes after ZK loader creates this component, initializes it and composes all its children, if any.

comp - the component has been composed

Copyright © 2005-2011 Potix Corporation. All Rights Reserved. Logo