public class CollectionTemplate extends Object implements org.zkoss.zk.ui.ext.DynamicPropertied, Serializable
ForEach, for
example, setModel(ListModel) corresponds to ForEach.setItems(Object) but only accept ListModel.
One difference is that developers can specify the template name by setTemplate(String) or setTemplateURI(String),
and it is more flexible to assign CollectionTemplateResolver which will resolve the proper Template by 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.
| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
apply(org.zkoss.zk.ui.Component host)
Compose the specified template with the given host.
|
Map<String,Object> |
getDynamicProperties() |
Object |
getDynamicProperty(String name) |
org.zkoss.zul.ListModel |
getModel() |
org.zkoss.zk.ui.Component |
getShadowHost()
Return the current shadow host.
|
String |
getTemplate()
Returns the template name
|
String |
getTemplateURI() |
boolean |
hasDynamicProperty(String name) |
void |
setDynamicProperty(String name,
Object value) |
void |
setModel(org.zkoss.zul.ListModel model)
Accept model to render iteratively.
|
void |
setTemplate(String template)
Sets the template name to apply.
|
void |
setTemplateResolver(CollectionTemplateResolver templateResolver)
Template resolver will resolve the proper
Template by evaluating the variable reference from model. |
void |
setTemplateURI(String templateURI)
Sets the template uri.
|
public CollectionTemplate(boolean autodrop)
autodrop - a boolean valuepublic org.zkoss.zk.ui.Component getShadowHost()
public void setModel(org.zkoss.zul.ListModel model)
model - public org.zkoss.zul.ListModel getModel()
public void setTemplateResolver(CollectionTemplateResolver templateResolver)
Template by evaluating the variable reference from model.templateResolver - public String getTemplate()
public void setTemplate(String template)
One cannot set both template and template URI at the same time. For example, setTemplate(String)
after setTemplateURI(String), then only template uri takes charge of rendering.
template - the template namepublic void setTemplateURI(String templateURI)
One cannot set both template and template URI at the same time. For example, setTemplate(String)
after setTemplateURI(String), then only template uri takes charge of rendering.
templateURI - the template URI, like Apply.setTemplateURI(String).public String getTemplateURI()
public void apply(org.zkoss.zk.ui.Component host)
host - as known as shadow host mentioned in other shadow elementpublic boolean hasDynamicProperty(String name)
hasDynamicProperty in interface org.zkoss.zk.ui.ext.DynamicPropertiedpublic Object getDynamicProperty(String name)
getDynamicProperty in interface org.zkoss.zk.ui.ext.DynamicPropertiedCopyright © 2020. All rights reserved.