public class CollectionTemplate extends java.lang.Object implements DynamicPropertied, java.io.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(Component host)
Compose the specified template with the given host.
|
java.util.Map<java.lang.String,java.lang.Object> |
getDynamicProperties() |
java.lang.Object |
getDynamicProperty(java.lang.String name)
Returns the property value of the specified name.
|
ListModel |
getModel() |
Component |
getShadowHost()
Return the current shadow host.
|
java.lang.String |
getTemplate()
Returns the template name
|
java.lang.String |
getTemplateURI() |
boolean |
hasDynamicProperty(java.lang.String name)
Returns whether a dynamic property is defined.
|
void |
setDynamicProperty(java.lang.String name,
java.lang.Object value)
Sets a property with the specified name and value.
|
void |
setModel(ListModel model)
Accept model to render iteratively.
|
void |
setTemplate(java.lang.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(java.lang.String templateURI)
Sets the template uri.
|
public CollectionTemplate(boolean autodrop)
autodrop
- a boolean valuepublic Component getShadowHost()
public void setModel(ListModel model)
model
- public ListModel getModel()
public void setTemplateResolver(CollectionTemplateResolver templateResolver)
Template
by evaluating the variable reference from model.templateResolver
- public java.lang.String getTemplate()
public void setTemplate(java.lang.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(java.lang.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 java.lang.String getTemplateURI()
public void apply(Component host)
host
- as known as shadow host mentioned in other shadow elementpublic boolean hasDynamicProperty(java.lang.String name)
DynamicPropertied
hasDynamicProperty
in interface DynamicPropertied
public java.lang.Object getDynamicProperty(java.lang.String name)
DynamicPropertied
getDynamicProperty
in interface DynamicPropertied
public java.util.Map<java.lang.String,java.lang.Object> getDynamicProperties()
public void setDynamicProperty(java.lang.String name, java.lang.Object value) throws WrongValueException
DynamicPropertied
If a component supports only String-type values, it could use org.zkoss.lang.Objects.toString() to convert the value to a String instance.
setDynamicProperty
in interface DynamicPropertied
WrongValueException
Copyright © 2005-2018 Potix Corporation. All Rights Reserved.