Class CollectionTemplate
- java.lang.Object
-
- org.zkoss.zuti.zul.CollectionTemplate
-
- All Implemented Interfaces:
java.io.Serializable,org.zkoss.zk.ui.ext.DynamicPropertied
public class CollectionTemplate extends java.lang.Object implements org.zkoss.zk.ui.ext.DynamicPropertied, java.io.SerializableA utility to let developers to apply shadow elements in Java class. It has the similar behavior withForEach, for example,setModel(ListModel)corresponds toForEach.setItems(Object)but only acceptListModel.One difference is that developers can specify the template name by
setTemplate(String)orsetTemplateURI(String), and it is more flexible to assignCollectionTemplateResolverwhich will resolve the properTemplateby evaluating the variable reference from model in runtime.Besides, developers must designate a boolean value, called autodrop, to indicate whether to drop those rendered children or not. If true, every time developers changed template or detach from the original host, ShadowTemplate will
HtmlShadowElement.recreate()or removed the children, otherwise, rendered children will remain on page.After instantiating CollectionTemplate instance and above configuration, developers can trigger
apply(Component)to compose the specified template with shadow host passed as parameter. Note that, the passed host should be the same one if autodrop is true, or pass null to detach the original host first.- Since:
- 8.0.0
- Author:
- chunfu
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CollectionTemplate(boolean autodrop)Constructor needs a boolean value to indicate whether to detached all rendered children automatically or not when template or host is changed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapply(org.zkoss.zk.ui.Component host)Compose the specified template with the given host.java.util.Map<java.lang.String,java.lang.Object>getDynamicProperties()java.lang.ObjectgetDynamicProperty(java.lang.String name)org.zkoss.zul.ListModelgetModel()org.zkoss.zk.ui.ComponentgetShadowHost()Return the current shadow host.java.lang.StringgetTemplate()Returns the template namejava.lang.StringgetTemplateURI()booleanhasDynamicProperty(java.lang.String name)voidsetDynamicProperty(java.lang.String name, java.lang.Object value)voidsetModel(org.zkoss.zul.ListModel model)Accept model to render iteratively.voidsetTemplate(java.lang.String template)Sets the template name to apply.voidsetTemplateResolver(CollectionTemplateResolver templateResolver)Template resolver will resolve the properTemplateby evaluating the variable reference from model.voidsetTemplateURI(java.lang.String templateURI)Sets the template uri.
-
-
-
Method Detail
-
getShadowHost
public org.zkoss.zk.ui.Component getShadowHost()
Return the current shadow host.- Returns:
- host component
-
setModel
public void setModel(org.zkoss.zul.ListModel model)
Accept model to render iteratively.- Parameters:
model-
-
getModel
public org.zkoss.zul.ListModel getModel()
-
setTemplateResolver
public void setTemplateResolver(CollectionTemplateResolver templateResolver)
Template resolver will resolve the properTemplateby evaluating the variable reference from model.- Parameters:
templateResolver-
-
getTemplate
public java.lang.String getTemplate()
Returns the template name
-
setTemplate
public void setTemplate(java.lang.String template)
Sets the template name to apply.One cannot set both template and template URI at the same time. For example,
setTemplate(String)aftersetTemplateURI(String), then only template uri takes charge of rendering.- Parameters:
template- the template name
-
setTemplateURI
public void setTemplateURI(java.lang.String templateURI)
Sets the template uri.One cannot set both template and template URI at the same time. For example,
setTemplate(String)aftersetTemplateURI(String), then only template uri takes charge of rendering.- Parameters:
templateURI- the template URI, likeApply.setTemplateURI(String).
-
getTemplateURI
public java.lang.String getTemplateURI()
-
apply
public void apply(org.zkoss.zk.ui.Component host)
Compose the specified template with the given host. Notice that,- If autodrop(the boolean value passed when instantiation) is true, users should apply to the same host every time, otherwise, apply null to detach the original host, and then apply to the new one.
- If autodrop is false, don't have to consider this situation, users can apply to any host you want except null.
- Parameters:
host- as known as shadow host mentioned in other shadow element
-
hasDynamicProperty
public boolean hasDynamicProperty(java.lang.String name)
- Specified by:
hasDynamicPropertyin interfaceorg.zkoss.zk.ui.ext.DynamicPropertied
-
getDynamicProperty
public java.lang.Object getDynamicProperty(java.lang.String name)
- Specified by:
getDynamicPropertyin interfaceorg.zkoss.zk.ui.ext.DynamicPropertied
-
getDynamicProperties
public java.util.Map<java.lang.String,java.lang.Object> getDynamicProperties()
- Specified by:
getDynamicPropertiesin interfaceorg.zkoss.zk.ui.ext.DynamicPropertied
-
setDynamicProperty
public void setDynamicProperty(java.lang.String name, java.lang.Object value) throws org.zkoss.zk.ui.WrongValueException- Specified by:
setDynamicPropertyin interfaceorg.zkoss.zk.ui.ext.DynamicPropertied- Throws:
org.zkoss.zk.ui.WrongValueException
-
-