|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.zk.ui.event.GenericEventListener org.zkoss.zk.ui.util.GenericComposer<T> org.zkoss.zk.ui.util.GenericAutowireComposer<T>
public abstract class GenericAutowireComposer<T extends Component>
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
SelectorComposer
.GenericForwardComposer
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>
ConventionWires
,
Serialized FormField Summary | |
---|---|
protected char |
_separator
The separator used to separate the component ID and event name. |
protected WebApp |
application
Implicit Object; the web application. |
protected java.util.Map<java.lang.String,java.lang.Object> |
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<java.lang.String,java.lang.Object> |
componentScope
Implicit Object; a map of attributes defined in the applied component. |
protected Desktop |
desktop
Implicit Object; the desktop. |
protected java.util.Map<java.lang.String,java.lang.Object> |
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<java.lang.String,java.lang.Object> |
pageScope
Implicit Object; a map of attributes defined in the page. |
protected java.util.Map<java.lang.String,java.lang.String[]> |
param
Implicit Object; the param argument passed from the http request. |
protected java.util.Map<java.lang.String,java.lang.Object> |
requestScope
Implicit Object; a map of attributes defined in the request. |
protected T |
self
Implicit Object; the applied component itself. |
protected Session |
session
Implicit Object; the session. |
protected java.util.Map<java.lang.String,java.lang.Object> |
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<java.lang.String,java.lang.Object> |
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()
The default constructor. |
protected |
GenericAutowireComposer(char separator)
Constructor with a custom separator. |
protected |
GenericAutowireComposer(char separator,
boolean ignoreZScript,
boolean ignoreXel)
Constructors with full control, including separator, whether to search zscript and xel variables |
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(T 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. |
protected Page |
getPage()
Returns the current page. |
java.lang.Object |
willClone(Component comp)
Internal use only. |
void |
willPassivate(Component comp)
Called when a session is about to be passivated (and then serialize its value). |
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 |
Field Detail |
---|
protected transient T extends Component self
protected transient IdSpace spaceOwner
protected transient Page page
protected transient Desktop desktop
protected transient Session session
protected transient WebApp application
protected transient java.util.Map<java.lang.String,java.lang.Object> componentScope
protected transient java.util.Map<java.lang.String,java.lang.Object> spaceScope
protected transient java.util.Map<java.lang.String,java.lang.Object> pageScope
protected transient java.util.Map<java.lang.String,java.lang.Object> desktopScope
protected transient java.util.Map<java.lang.String,java.lang.Object> sessionScope
protected transient java.util.Map<java.lang.String,java.lang.Object> applicationScope
protected transient java.util.Map<java.lang.String,java.lang.Object> requestScope
protected transient Execution execution
protected transient java.util.Map<?,?> arg
protected transient java.util.Map<java.lang.String,java.lang.String[]> param
protected char _separator
Constructor Detail |
---|
protected GenericAutowireComposer()
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
If you want to control whether to wire ZSCRIPT's or XEL's variable
explicitly, you could use
GenericAutowireComposer(char,boolean,boolean)
instead.
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).
protected GenericAutowireComposer(char separator)
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
If you want to control whether to wire ZSCRIPT's or XEL's variable
explicitly, you could use
GenericAutowireComposer(char,boolean,boolean)
instead.
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).
separator
- the separator used to separate the component ID and event name.
Refer to _separator
for details.protected GenericAutowireComposer(char separator, boolean ignoreZScript, boolean ignoreXel)
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.Method Detail |
---|
protected Page getPage()
getPage
in class GenericComposer<T extends Component>
public void doAfterCompose(T comp) throws java.lang.Exception
doAfterCompose
in interface Composer<T extends Component>
doAfterCompose
in class GenericComposer<T extends Component>
comp
- the component has been composed
java.lang.Exception
protected void alert(java.lang.String m)
public java.lang.Object willClone(Component comp)
willClone
in interface ComponentCloneListener
comp
- the clone of the applied component
public void didActivate(Component comp)
ComponentActivationListener
didActivate
in interface ComponentActivationListener
public void willPassivate(Component comp)
ComponentActivationListener
willPassivate
in interface ComponentActivationListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |