|
||||||||||
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>
public abstract class GenericComposer<T extends Component>
A skeletal composer that you can extend and write intuitive onXxx event handler methods; this class will registers onXxx events to the supervised component automatically.
Alternatives: in most cases, you don't extend from GenericComposer
directly.
Rather, you can extend from one of the following skeletons.
SelectorComposer
SelectorComposer
.GenericForwardComposer
The following is an example. The onOK and onCancel event listener is registered into the target main window automatically.
<zscript><!-- both OK in zscript or a compiled Java class -->
public class MyComposer extends GenericComposer {
public void onOK() {
//doOK!
//...
}
public void onCancel() {
//doCancel
//...
}
}
</zscript>
<window id="main" apply="MyComposer">
...
</window>
since 3.6.1, this composer would be assigned as an attribute of the given component
per the naming convention composed of the component id and composer Class name. e.g.
If the applied component id is "xwin" and this composer class is
org.zkoss.MyComposer, then the variable name would be "xwin$MyComposer". You can
reference this composer with Component.getAttributeOrFellow(java.lang.String, boolean)
or via EL as ${xwin$MyComposer}
of via annotate data binder as @{xwin$MyComposer}, etc. If this composer is the
first composer applied to the component, a shorter variable name
composed of the component id and a String "composer" would be also available for use.
Per the above example, you can also reference this composer with the name "xwin$composer".
In general, xwin$composer
is suggested because EL expressions won't
depend on the composer's class name. However, xwin$MyComposer
is
useful if you apply multiple composers to the same component.
Notice that, since 3.6.2, this composer becomes serializable.
Field Summary | |
---|---|
protected java.lang.String |
_applied
|
Constructor Summary | |
---|---|
GenericComposer()
|
Method Summary | |
---|---|
void |
doAfterCompose(T comp)
Registers onXxx events to the supervised component; a subclass that override this method should remember to call super.doAfterCompose(comp) or it will not work. |
ComponentInfo |
doBeforeCompose(Page page,
Component parent,
ComponentInfo compInfo)
Invokes before composing a component. |
void |
doBeforeComposeChildren(T comp)
Invokes after the component is instantiated and initialized, but before composing any child. |
boolean |
doCatch(java.lang.Throwable ex)
Called when an exception occurs when composing the component. |
void |
doFinally()
Called after the component has been composed completely. |
protected Page |
getPage()
Returns the current page. |
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 java.lang.String _applied
Constructor Detail |
---|
public GenericComposer()
Method Detail |
---|
protected Page getPage()
public void doAfterCompose(T comp) throws java.lang.Exception
doAfterCompose
in interface Composer<T extends Component>
comp
- the component has been composed
java.lang.Exception
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo)
ComposerExt
ComponentInfo.duplicate()
to make a copy and then
modify it such that it won't affect the default behavior.
doBeforeCompose
in interface ComposerExt<T extends Component>
page
- the page for composing this component.parent
- the parent component, or null if it is the root component.compInfo
- the component info used to instantiate the component.
Notice that it is null if the page is rendered as ZK JSP, since
ComponentInfo
is not available under ZK JSP.
public void doBeforeComposeChildren(T comp) throws java.lang.Exception
ComposerExt
doBeforeComposeChildren
in interface ComposerExt<T extends Component>
comp
- the component being composed
java.lang.Exception
public boolean doCatch(java.lang.Throwable ex) throws java.lang.Exception
ComposerExt
If you don't want to handle the exception, simply returns false.
boolean doCatch(Throwable ex) {return false;}
An exception thrown in this method is simply logged. It has no effect on the execution. If you want to ignore the exception, just return true.
doCatch
in interface ComposerExt<T extends Component>
ex
- the exception being thrown
java.lang.Exception
public void doFinally() throws java.lang.Exception
ComposerExt
Note: it is always called even if ComposerExt.doCatch(java.lang.Throwable)
,
ComposerExt.doBeforeComposeChildren(T)
or
Composer.doAfterCompose(T)
is not called (due to exceptions).
Note: it is called after the onCreate event is posted, but before the onCreate and any other events are handled.
An exception thrown in this method is simply logged. It has no effect on the execution.
doFinally
in interface ComposerExt<T extends Component>
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |