Class CollectionTemplate
- All Implemented Interfaces:
Serializable,DynamicPropertied
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.
- Since:
- 8.0.0
- Author:
- chunfu
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCollectionTemplate(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
Modifier and TypeMethodDescriptionvoidCompose the specified template with the given host.Returns all available dynamic properties.getDynamicProperty(String name) Returns the property value of the specified name.getModel()Return the current shadow host.Returns the template namebooleanhasDynamicProperty(String name) Returns whether a dynamic property is defined.voidsetDynamicProperty(String name, Object value) Sets a property with the specified name and value.voidAccept model to render iteratively.voidsetTemplate(String template) Sets the template name to apply.voidsetTemplateResolver(CollectionTemplateResolver templateResolver) Template resolver will resolve the properTemplateby evaluating the variable reference from model.voidsetTemplateURI(String templateURI) Sets the template uri.
-
Constructor Details
-
CollectionTemplate
public 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.- Parameters:
autodrop- a boolean value
-
-
Method Details
-
getShadowHost
Return the current shadow host.- Returns:
- host component
-
setModel
Accept model to render iteratively.- Parameters:
model-
-
getModel
-
setTemplateResolver
Template resolver will resolve the properTemplateby evaluating the variable reference from model.- Parameters:
templateResolver-
-
getTemplate
Returns the template name -
setTemplate
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
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
-
apply
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
Description copied from interface:DynamicPropertiedReturns whether a dynamic property is defined.- Specified by:
hasDynamicPropertyin interfaceDynamicPropertied
-
getDynamicProperty
Description copied from interface:DynamicPropertiedReturns the property value of the specified name.- Specified by:
getDynamicPropertyin interfaceDynamicPropertied
-
getDynamicProperties
Description copied from interface:DynamicPropertiedReturns all available dynamic properties.- Specified by:
getDynamicPropertiesin interfaceDynamicPropertied
-
setDynamicProperty
Description copied from interface:DynamicPropertiedSets a property with the specified name and value.If a component supports only String-type values, it could use org.zkoss.lang.Objects.toString() to convert the value to a String instance.
- Specified by:
setDynamicPropertyin interfaceDynamicPropertied- Throws:
WrongValueException
-