Class ComponentInfo
- All Implemented Interfaces:
Serializable,NodeInfo,Condition
- Direct Known Subclasses:
NativeInfo
Though serializable, we can restore NodeInfo.getPageDefinition()
correctly after deserialized.
Note:it is not thread-safe.
It is serializable.
- Author:
- tomyeh
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionComponentInfo(NodeInfo parent, ComponentDefinition compdef, String tag) Constructs the information about how to create component. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(String propName, String annotName, Map<String, String[]> annotAttrs, org.zkoss.util.resource.Location loc) Adds an annotation to the specified property of this component info.voidaddEventHandler(String name, ZScript zscript, ConditionImpl cond) Adds an event handler.voidaddProperty(String name, String value, ConditionImpl cond) Adds a property initializer.voidaddProperty(String name, NativeInfo value, ConditionImpl cond) Adds a property initializer based on the native content.voidaddWidgetAttribute(String name, String value, ConditionImpl cond) Adds a custom DOM attribute to the peer widget.voidaddWidgetListener(String name, String script, ConditionImpl cond) Adds an event listener for the peer widget.voidaddWidgetOverride(String name, String script, ConditionImpl cond) Adds a method or a value to the peer widget.voidappendChild(NodeInfo child) Adds a child.voidapplyProperties(Component comp) Applies the event handlers and properties to the specified component.voidDuplicates the specified component info but retaining the same but virtual parent-child relationship.voidEvaluates and retrieves properties to the specified map fromComponentDefinition(andComponentInfo).Returns the annotation map defined in this info, or null if no annotation is ever defined.getApply()Returns the apply attribute that is a list ofComposerclass names or EL expressions returning classes, class names or composer instances, or null if no apply attribute.Returns a readonly list of children.Returns the component definition, or null if it is PageDefinition.Returns the effectiveness condition.Returns the evaluator.Returns the evaluator reference.Returns a readonly collection of event names (String), or an empty collection if no event name is registered.Returns the forward condition that controls how to forward an event, that is received by the component created by this info, to another component.Returns the fulfill condition that controls when to create the child components, or null if the child components are created at the time when the page is loaded.Returns the class name or an expression returning a class instance, a class name, or a component.Returns the language definition thatgetComponentDefinition()belongs to, or null if the component definition is temporary.Returns the page definition, i.e., the root node, or null if not available.Returns the parent, or null if it has no parent.Returns a readonly list of properties (Property) (never null).Returns the replaceable text, nor null if it cannot be replaced with a text.getTag()Returns the tag name, or null if no tag name.Returns the property name to which the text enclosed within the element (associated with this component definition) is assigned to.Returns the widget class (might contain EL expressions), or null if not available.booleanbooleanReturns whether to preserve the blank text.booleanReturns if a child is allowed in the text-as area.booleanisEffective(Component comp) Used to evaluate whether it is effective.booleanisEffective(Page page) Used to evaluate whether it is effective.newInstance(Page page) Creates an component based on this info (never null).newInstance(Page page, Component parent) Creates an component based on this info (never null).booleanremoveChild(NodeInfo child) Removes a child.resolveComposer(Page page, Component comp) Returns the composer for this info, or null if not available.resolveForEach(Page page, Component comp) Returns the forEach object if the forEach attribute is defined (orForEachBranchInfo.setForEach(java.lang.String, java.lang.String, java.lang.String)is called).Resolves and returns the class for the component represented by this info (never null).resolveImplementationClass(Page page, Component parent) Resolves and returns the class for the component represented by this info (never null).resolveWidgetClass(Component comp) Resolves the widget class, or null if the default is expected.voidSets the apply attribute that is is a list ofComposerclass or EL expressions returning classes, class names or composer instances.voidsetCondition(ConditionImpl cond) Sets the effectiveness condition.voidsetForEach(String expr, String begin, String end) Sets the forEach attribute, which is usually an expression.voidsetForEach(String expr, String begin, String end, String step) Sets the forEach attribute, which is usually an expression.voidsetForward(String forward) Sets the forward condition that controls when to forward an event receiving by this component to another component.voidsetFulfill(String fulfill) Sets the fulfill condition that controls when to create the child components.voidsetImplementation(String expr) Sets the string that implements the component.voidsetReplaceableText(String text) Sets the replaceable text.voidsetWidgetClass(String wgtcls) Sets the widget class.toString()booleanTests if the condition is setbooleanReturns whether the forEach condition is defined.
-
Constructor Details
-
ComponentInfo
Constructs the information about how to create component.- Parameters:
parent- the parent; never null.compdef- the component definition; never nulltag- the tag name; Note: if component implementsDynamicTag, this argument must be specified. IfDynamicTagis not implemented, this argument is optional.
-
-
Method Details
-
getLanguageDefinition
Returns the language definition thatgetComponentDefinition()belongs to, or null if the component definition is temporary. -
getComponentDefinition
Returns the component definition, or null if it is PageDefinition. -
appendChild
Adds a child.- Specified by:
appendChildin interfaceNodeInfo- Throws:
IllegalStateException- if this is not an instance ofNativeInfoand the child isTextInfo.
-
getTag
Returns the tag name, or null if no tag name.- Since:
- 3.0.0
-
getTextAs
Returns the property name to which the text enclosed within the element (associated with this component definition) is assigned to.Default: the same as
ComponentDefinition.getTextAs().- Since:
- 3.0.0
- See Also:
-
isChildAllowedInTextAs
public boolean isChildAllowedInTextAs()Returns if a child is allowed in the text-as area. It is meaningful only ifgetTextAs()is not null. If true, the text enclosed within the element is considered as text only if there is no other XML element.For example, <div> in the following example won't be considered as text. Rather, a div component will be created.
<a> <div>...</div> </a>Default: the same as
ComponentDefinition.isChildAllowedInTextAs().- Since:
- 6.0.0
- See Also:
-
isBlankPreserved
public boolean isBlankPreserved()Returns whether to preserve the blank text. If false, the blank text (a non-empty string consisting of whitespaces) are ignored. If true, they are converted to a label child.Default: false.
- Since:
- 3.5.0
-
getReplaceableText
Returns the replaceable text, nor null if it cannot be replaced with a text.By replaceable text we mean the component can be replaced by a text (a.k.a., string). ZK uses it to optimize the output by generating some content directly.
The replaceable text must be a string consisting of whitespaces only.
- Since:
- 3.5.0
- See Also:
-
setReplaceableText
Sets the replaceable text.- Parameters:
text- the text that can be used to replace the component being generated by this info. If null, it means no way to replace it with text.- Since:
- 3.5.0
- See Also:
-
getFulfill
Returns the fulfill condition that controls when to create the child components, or null if the child components are created at the time when the page is loaded.Default: null.
There are several forms:
"eventName", "targetId.evetName", "id1/id2.evetName", and "${elExpr}.eventName".Since 3.0.2, you can specify a list of fulfill conditions by separating them with comma. For example:
"id1.event1, id2/id3.event2"If not null, the child components specified in
getChildren()are created, when the event specified in the fulfill condition is received at the first time.It is the value specified in the fulfill attribute.
- Since:
- 2.4.0
-
setFulfill
Sets the fulfill condition that controls when to create the child components.If not null, the child components specified in
getChildren()are created, when the event specified in the fulfill condition is received at the first time.- Parameters:
fulfill- the fulfill condition. There are several forms:
"eventName", "targetId.evetName", "id1/id2.evetName", and "${elExpr}.eventName".Since 3.0.2, you can specify a list of fulfill conditions by separating them with comma. For example:
"id1.event1, id2/id3.event2"Since 3.5.0, you can specify the URI to fulfill with. For example:
"id1.event1=/my/super.zul".- Since:
- 2.4.0
-
resolveComposer
Returns the composer for this info, or null if not available.- Parameters:
comp- the component used as the self variable to resolve EL expressions, if any. Notice that UI engine uses the parent component for this argument. If comp is null, the page is used as the parent component. If comp is not null, it is used as the self variable.- Since:
- 3.5.0
- See Also:
-
getApply
Returns the apply attribute that is a list ofComposerclass names or EL expressions returning classes, class names or composer instances, or null if no apply attribute.- Since:
- 3.0.0
- See Also:
-
setApply
Sets the apply attribute that is is a list ofComposerclass or EL expressions returning classes, class names or composer instances.- Parameters:
apply- the attribute this is a list ofComposerclass or EL expressions El expressions are allowed, but self means the parent, if available; or page, if no parent at all. (Note: the component is not created yet when the apply attribute is evaluated).- Since:
- 3.0.0
-
getForward
Returns the forward condition that controls how to forward an event, that is received by the component created by this info, to another component.Default: null.
If not null, when the component created by this info receives the event specified in the forward condition, it will forward it to the target component, which is also specified in the forward condition.
- Since:
- 3.0.0
- See Also:
-
setForward
Sets the forward condition that controls when to forward an event receiving by this component to another component.The basic format:
onEvent1=id1/id2.onEvent2It means when onEvent1 is received, onEvent2 will be posted to the component with the specified path (id1/id2).
If onEvent1 is omitted, it is assumed to be onClick (and the equal sign need not to be specified. If the path is omitted, it is assumed to be the space owner
Component.getSpaceOwner().For example, "onOK" means "onClick=onOK".
You can specify several forward conditions by separating them with comma as follows:
onChanging=onChanging,onChange=onUpdate,onOK- Parameters:
forward- the forward condition. There are several forms: "onEvent1", "target.onEvent1" and "onEvent1(target.onEvent2)", where target could be "id", "id1/id2" or "${elExpr}". The EL expression must return either a path or a reference to a component.- Since:
- 3.0.0
-
getProperties
Returns a readonly list of properties (Property) (never null).- Since:
- 2.4.0
-
addProperty
Adds a property initializer. It will initialize a component when created with this info.- Parameters:
name- the member name. The component must have a valid setter for it.value- the value. It might contain expressions (${}).
-
addProperty
Adds a property initializer based on the native content. The native content is a XML fragment represented byNativeInfo.- Parameters:
value- the property value represented byNativeInfo.- Since:
- 3.5.0
-
addEventHandler
Adds an event handler.- Parameters:
name- the event name.zscript- the script.
-
getEventHandlerNames
Returns a readonly collection of event names (String), or an empty collection if no event name is registered.To add an event handler, use
addEventHandler(java.lang.String, org.zkoss.zk.ui.metainfo.ZScript, org.zkoss.zk.ui.util.ConditionImpl)instead.- Since:
- 3.0.2
-
addWidgetListener
Adds an event listener for the peer widget.- Since:
- 5.0.0
-
addWidgetOverride
Adds a method or a value to the peer widget. If there was a method with the same name, it will be renamed to$nameso can you access it for callback purpose.<label w:setValue="function (value) { this.$setValue(value); //old method }"/>- Parameters:
script- the client side script. EL expressions are allowed.- Since:
- 5.0.0
- See Also:
-
addWidgetAttribute
Adds a custom DOM attribute to the peer widget.Unlike
addWidgetOverride(java.lang.String, java.lang.String, org.zkoss.zk.ui.util.ConditionImpl), the attributes added here are generated directly as DOM attributes at the client. In other words, it is not a property or method of the peer widget.- Parameters:
name- the name of the attribute. UnlikeaddWidgetOverride(java.lang.String, java.lang.String, org.zkoss.zk.ui.util.ConditionImpl), the name might contain no alphanumeric characters, such as colon and dash.- Since:
- 5.0.3
- See Also:
-
setWidgetClass
Sets the widget class.- Parameters:
wgtcls- the widget class (at the client side). EL expressions are allowed.- Since:
- 5.0.2
-
getWidgetClass
Returns the widget class (might contain EL expressions), or null if not available.- Since:
- 5.0.2
-
resolveWidgetClass
Resolves the widget class, or null if the default is expected. It will evaluate EL expressions if any.You rarely need to invoke this method since it is called automatically when
applyProperties(org.zkoss.zk.ui.Component)is called.- Parameters:
comp- the component that the widget class represents at the client.- Since:
- 5.0.2
-
getImplementation
Returns the class name or an expression returning a class instance, a class name, or a component. It is the same value thatsetImplementation(java.lang.String)was called. To resolve the real implementation class, useresolveImplementationClass(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component).Notice that, if a component is returned by the expression, it shall not be assigned to any page.
- Since:
- 3.6.0
-
setImplementation
Sets the string that implements the component.- Parameters:
expr- the class name, or an expression returning a class instance, a class name, or a component instance.- Since:
- 3.6.0
-
newInstance
Creates an component based on this info (never null).Like
ComponentDefinition.newInstance(org.zkoss.zk.ui.Page, java.lang.String), this method doesn't invokeapplyProperties(org.zkoss.zk.ui.Component). It is caller's job to invoke them if necessary. Since the value of properties might depend on the component tree, it is better to assign the component with a proper parent before callingapplyProperties(org.zkoss.zk.ui.Component).- Since:
- 3.0.2
-
newInstance
Creates an component based on this info (never null). It is the same as newInstance(page, null).If the implementation class (
getImplementation()) doesn't have any EL expression, or its EL expression doesn't have reference to the self variable, the result is the same.This method is preserved for backward compatibility. It is better to use
newInstance(Page, Component). -
resolveImplementationClass
Resolves and returns the class for the component represented by this info (never null).Unlike
getImplementation(), this method will resolve a class name (String) to a class (Class), if necessary.- Parameters:
page- the page to check whether the class is defined in the page (such as interpreters). Ignored if null. This method will search the class loader of the current thread. If not found, it will search the interpreters of the specified page (Page.getLoadedInterpreters()). Note: this method won't attach the component to the specified page.- Throws:
ClassNotFoundException- if the class not found- Since:
- 3.0.2
-
resolveImplementationClass
Resolves and returns the class for the component represented by this info (never null). It is the same as resolveImplementationClass(page, null).If the implementation class (
getImplementation()) doesn't have any EL expression, or its EL expression doesn't have reference to the self variable, the result is the same.This method is preserved for backward compatibility. It is better to use
resolveImplementationClass(Page, Component).- Throws:
ClassNotFoundException- Since:
- 3.0.0
-
getAnnotationMap
Returns the annotation map defined in this info, or null if no annotation is ever defined. -
applyProperties
Applies the event handlers and properties to the specified component.It also invokes
ComponentDefinition.applyProperties(org.zkoss.zk.ui.Component).Note: custom attributes are not part of
ComponentInfo, so they won't be applied here.Note: annotations are applied to the component when a component is created. So, this method doesn't and need not to copy them. See also
AbstractComponent(boolean).Note: the widget class (
setWidgetClass(java.lang.String)) is set by this method.- Since:
- 3.0.0
-
evalProperties
public Map<String,Object> evalProperties(Map<String, Object> propmap, Page owner, Component parent, boolean defIncluded) Evaluates and retrieves properties to the specified map fromComponentDefinition(andComponentInfo).- Parameters:
propmap- the map to store the retrieved properties (String name, Object value). If null, a HashMap instance is created.owner- the owner page; used if parent is nullparent- the parent component (may be null)defIncluded- whether to callComponentDefinition.evalProperties(java.util.Map<java.lang.String, java.lang.Object>, org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component).
-
addAnnotation
public void addAnnotation(String propName, String annotName, Map<String, String[]> annotAttrs, org.zkoss.util.resource.Location loc) Adds an annotation to the specified property of this component info.- Parameters:
propName- the property name. If null, the annotation is associated with the whole component rather than a particular property.annotName- the annotation name (never null, nor empty).annotAttrs- a map of attributes, or null if no attribute at all. The attribute must be in a pair of strings (String name, String value), or (String name, String[] value).loc- the location information of the annotation in the document, or null if not available.- Since:
- 6.0.0
-
duplicate
Duplicates the specified component info but retaining the same but virtual parent-child relationship. It is designed to use withComposerExt.doBeforeCompose(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.metainfo.ComponentInfo)to override some properties of the default component info.Unlike
Object.clone(), the parent-child relation is duplicated but it is 'virtual'. By virtual we mean all the children's parent doesn't reference to the duplicated info (the returned instance). Rather, they reference to the original info being duplicated.Since the parent-children relation of the returned info is 'virtual', you can not call
appendChild(org.zkoss.zk.ui.metainfo.NodeInfo)or others to change it. If you need to change the parent-children relation, useObject.clone()instead, and then clone the required children.Notice, we actually copy the values to the returned info so any change to the original one doesn't affect the duplicated info.
- Since:
- 3.0.8
- See Also:
-
toString
-
hasBindingAnnotation
public boolean hasBindingAnnotation() -
enableBindingAnnotation
public void enableBindingAnnotation() -
disableBindingAnnotation
public void disableBindingAnnotation() -
resolveForEach
Returns the forEach object if the forEach attribute is defined (orForEachBranchInfo.setForEach(java.lang.String, java.lang.String, java.lang.String)is called).If comp is not null, both pagedef and page are ignored. If comp is null, page must be specified.
- Parameters:
page- the page. It is used only if comp is null.comp- the component.- Returns:
- the forEach object to iterate this info multiple times, or null if this info shall be interpreted only once.
-
setForEach
Sets the forEach attribute, which is usually an expression.- Parameters:
expr- the expression to return a collection of objects, or null/empty to denote no iteration.
-
setForEach
Sets the forEach attribute, which is usually an expression.- Parameters:
expr- the expression to return a collection of objects, or null/empty to denote no iteration.- Since:
- 8.0.0
-
withForEach
public boolean withForEach()Returns whether the forEach condition is defined. -
getCondition
Returns the effectiveness condition. -
setCondition
Sets the effectiveness condition. -
withCondition
public boolean withCondition()Tests if the condition is set -
removeChild
Description copied from interface:NodeInfoRemoves a child.- Specified by:
removeChildin interfaceNodeInfo
-
getChildren
Description copied from interface:NodeInfoReturns a readonly list of children.Note: the returned list is readonly. To modify, please use
NodeInfo.appendChild(org.zkoss.zk.ui.metainfo.NodeInfo)andNodeInfo.removeChild(org.zkoss.zk.ui.metainfo.NodeInfo)instead.- Specified by:
getChildrenin interfaceNodeInfo
-
isEffective
Description copied from interface:ConditionUsed to evaluate whether it is effective.- Specified by:
isEffectivein interfaceCondition- Parameters:
comp- used as the self variable. Ignored if null.
-
isEffective
Description copied from interface:ConditionUsed to evaluate whether it is effective.- Specified by:
isEffectivein interfaceCondition- Parameters:
page- used as the self variable. Ignored if null.
-
getEvaluatorRef
Description copied from interface:NodeInfoReturns the evaluator reference.- Specified by:
getEvaluatorRefin interfaceNodeInfo
-
getPageDefinition
Description copied from interface:NodeInfoReturns the page definition, i.e., the root node, or null if not available.- Specified by:
getPageDefinitionin interfaceNodeInfo
-
getEvaluator
Description copied from interface:NodeInfoReturns the evaluator.All nodes in the same ZUML tree has the same evaluator reference (inherited from the root node,
PageDefinition.getEvaluatorRef()).- Specified by:
getEvaluatorin interfaceNodeInfo
-
getParent
Description copied from interface:NodeInfoReturns the parent, or null if it has no parent.
-