Class GenericComposer<T extends Component>
- All Implemented Interfaces:
Serializable,EventListener,SerializableEventListener,Composer<T>,ComposerExt<T>
- Direct Known Subclasses:
GenericAutowireComposer
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- 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 properly.
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.
- Since:
- 3.0.1
- Author:
- robbiecheng
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddoAfterCompose(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.doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) Invokes before composing a component.voiddoBeforeComposeChildren(T comp) Invokes after the component is instantiated and initialized, but before composing any child.booleanCalled when an exception occurs when composing the component.voidCalled after the component has been composed completely.protected PagegetPage()Returns the current page.Methods inherited from class org.zkoss.zk.ui.event.GenericEventListener
bindComponent, getController, onEvent, unbindComponent
-
Field Details
-
_applied
-
-
Constructor Details
-
GenericComposer
public GenericComposer()
-
-
Method Details
-
getPage
Returns the current page.- Since:
- 5.0.10
-
doAfterCompose
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.- Specified by:
doAfterComposein interfaceComposer<T extends Component>- Parameters:
comp- the component has been composed- Throws:
Exception
-
doBeforeCompose
Description copied from interface:ComposerExtInvokes before composing a component. If you want to manipulate the specified component info, you can useComponentInfo.duplicate()to make a copy and then modify it such that it won't affect the default behavior.- Specified by:
doBeforeComposein interfaceComposerExt<T extends Component>- Parameters:
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, sinceComponentInfois not available under ZK JSP.- Returns:
- the component info used to instantiate the component. In most case, it shall return compInfo. If null is returned, the component won't be instantiated. In other words, it is ignored.
-
doBeforeComposeChildren
Description copied from interface:ComposerExtInvokes after the component is instantiated and initialized, but before composing any child.- Specified by:
doBeforeComposeChildrenin interfaceComposerExt<T extends Component>- Parameters:
comp- the component being composed- Throws:
Exception
-
doCatch
Description copied from interface:ComposerExtCalled when an exception occurs when composing the component.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.
- Specified by:
doCatchin interfaceComposerExt<T extends Component>- Parameters:
ex- the exception being thrown- Returns:
- whether to ignore the exception. If false is returned, the exception will be re-thrown. Note: once a composer's doCatch returns true, the exception will be ignored and it means doCatch of the following composers won't be called.
- Throws:
Exception
-
doFinally
Description copied from interface:ComposerExtCalled after the component has been composed completely. It is the last step of the composing.Note: it is always called even if
ComposerExt.doCatch(java.lang.Throwable),ComposerExt.doBeforeComposeChildren(T)orComposer.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.
- Specified by:
doFinallyin interfaceComposerExt<T extends Component>- Throws:
Exception
-