public class CollectionModel extends StringModel implements TemplateCollectionModel, TemplateSequenceModel
|Constructor and Description|
Creates a new model that wraps the specified collection object.
|Modifier and Type||Method and Description|
Retrieves the i-th object from the collection, wrapped as a TemplateModel.
Retrieves a template model iterator that is used to iterate over the elements in this collection.
get, getAdaptedObject, getAPI, getWrappedObject, hasPlainGetMethod, invokeGenericGet, isEmpty, keys, keySet, toString, unwrap, values, wrap
public CollectionModel(Collection collection, BeansWrapper wrapper)
collection- the collection object to wrap into a model.
BeansWrapperassociated with this model. Every model has to have an associated
BeansWrapperinstance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.
public TemplateModel get(int index) throws TemplateModelException
nullif the index is out of bounds. Note that a
nullvalue is interpreted by FreeMarker as "variable does not exist", and accessing a missing variables is usually considered as an error in the FreeMarker Template Language, so the usage of a bad index will not remain hidden, unless the default value for that case was also specified in the template.
TemplateModelException- if the index is out of bounds, or the underlying collection is not a List.
public boolean getSupportsIndexedAccess()
get(int)will always fail for this object. As this object implements
get(int)should always work, but due to a design flaw, for non-
get(int)will always fail. This method exists to ease working this problem around.
public TemplateModelIterator iterator()