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
SelectorComposer
.GenericForwardComposer
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>
ConventionWires
,
Serialized Form_separator, application, applicationScope, arg, componentScope, desktop, desktopScope, execution, page, pageScope, param, requestScope, self, session, sessionScope, spaceOwner, spaceScope
_applied
Modifier | Constructor and 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.
|
Modifier and Type | Method and 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.
|
alert, didActivate, getPage, willClone, willPassivate
doBeforeCompose, doBeforeComposeChildren, doCatch, doFinally
bindComponent, getController, onEvent, unbindComponent
protected GenericForwardComposer()
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.
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).
protected GenericForwardComposer(char separator)
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.
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).
protected GenericForwardComposer(char separator, boolean ignoreZScript, boolean ignoreXel)
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.public void doAfterCompose(T comp) throws java.lang.Exception
doAfterCompose
in interface Composer<T extends Component>
doAfterCompose
in class GenericAutowireComposer<T extends Component>
comp
- the component has been composedjava.lang.Exception
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.