Class SelectorComposer<T extends Component>
- java.lang.Object
-
- org.zkoss.zk.ui.select.SelectorComposer<T>
-
- All Implemented Interfaces:
java.io.Serializable,ComponentActivationListener,ComponentCloneListener,Composer<T>,ComposerExt<T>
public class SelectorComposer<T extends Component> extends java.lang.Object implements Composer<T>, ComposerExt<T>, ComponentCloneListener, ComponentActivationListener, java.io.Serializable
A composer analogous to GenericForwardComposer. Instead of wiring variables and adding event listeners by naming convention, this composer do the work by annotation and selectors.
For example:
The selector syntax is analogous to CSS selector syntax. For example,MyComposer.java public class MyComposer extends SelectorComposer { @Wire("#win") private Window myWin; // implicit variables @WireVariable private Desktop desktop; @Listen("onClick = button#btn") public void onSubmit(Event event){ // do something ... } }@Wire("textbox") // matches all textboxes @Wire("#win") // matches components of id "#win" within the same IdSpace @Wire(".myclass") // matches components of sclass "myclass" @Wire("label[value = 'My Label']") // matches all labels with value "My Label" @Wire(":first-child") // matches all components which are first child @Wire("window textbox") // matches textbox who is a descendant of a window @Wire("window > textbox") // matches textbox who is a child of a window @Wire("window + textbox") // matches textbox who is the next sibling of a window @Wire("window ~ textbox") // matches textbox who is a younger sibling of a window @Wire("window > textbox.myclass:first-child") // conditions can be mixed- Since:
- 6.0.0
- Author:
- simonpai
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSelectorComposer.UtilityHandlerAn interface for SelectorComposer's functionality plug-in.static classSelectorComposer.UtilityHandlerImplDefault skeletal implementation ofSelectorComposer.UtilityHandler.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<org.zkoss.xel.VariableResolver>_resolversA list of resolvers (never null).
-
Constructor Summary
Constructors Constructor Description SelectorComposer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidalert(java.lang.String m)Shortcut to call Messagebox.show(String).voiddidActivate(Component comp)Called when a session has just been activated (and its value has been deserialized).voiddoAfterCompose(T comp)Invokes after ZK loader creates this component, initializes it and composes all its children, if any.ComponentInfodoBeforeCompose(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.booleandoCatch(java.lang.Throwable ex)Called when an exception occurs when composing the component.voiddoFinally()Called after the component has been composed completely.protected PagegetPage()Returns the current page.protected TgetSelf()Returns the component which applies to this composer.protected static SelectorComposer.UtilityHandlergetUtilityHandler()java.lang.ObjectwillClone(Component comp)Internal use only.voidwillPassivate(Component comp)Called when a session is about to be passivated (and then serialize its value).
-
-
-
Field Detail
-
_resolvers
protected final java.util.List<org.zkoss.xel.VariableResolver> _resolvers
A list of resolvers (never null). A variable resolver is added automatically ifVariableResolverwas annotated.
-
-
Method Detail
-
doBeforeCompose
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo)
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
public void doBeforeComposeChildren(T comp) throws java.lang.Exception
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:
java.lang.Exception
-
doAfterCompose
public void doAfterCompose(T comp) throws java.lang.Exception
Description copied from interface:ComposerInvokes after ZK loader creates this component, initializes it and composes all its children, if any.- Specified by:
doAfterComposein interfaceComposer<T extends Component>- Parameters:
comp- the component has been composed- Throws:
java.lang.Exception
-
getSelf
protected T getSelf()
Returns the component which applies to this composer.- Since:
- 6.0.1
-
getPage
protected Page getPage()
Returns the current page.
-
alert
protected void alert(java.lang.String m)
Shortcut to call Messagebox.show(String).
-
willClone
public java.lang.Object willClone(Component comp)
Internal use only. Call-back method of CloneComposerListener. You shall not call this method directly. Clone this Composer when its applied component is cloned.- Specified by:
willClonein interfaceComponentCloneListener- Parameters:
comp- the clone of the applied component- Returns:
- A clone of this Composer.
-
didActivate
public void didActivate(Component comp)
Description copied from interface:ComponentActivationListenerCalled when a session has just been activated (and its value has been deserialized).- Specified by:
didActivatein interfaceComponentActivationListener
-
willPassivate
public void willPassivate(Component comp)
Description copied from interface:ComponentActivationListenerCalled when a session is about to be passivated (and then serialize its value).- Specified by:
willPassivatein interfaceComponentActivationListener
-
doCatch
public boolean doCatch(java.lang.Throwable ex) throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
doFinally
public void doFinally() throws java.lang.ExceptionDescription 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:
java.lang.Exception
-
getUtilityHandler
protected static SelectorComposer.UtilityHandler getUtilityHandler()
-
-