Class CollectionModel

    • Constructor Detail

      • CollectionModel

        public CollectionModel​(Collection collection,
                               BeansWrapper wrapper)
        Creates a new model that wraps the specified collection object.
        Parameters:
        collection - the collection object to wrap into a model.
        wrapper - the BeansWrapper associated with this model. Every model has to have an associated BeansWrapper instance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.
    • Method Detail

      • get

        public TemplateModel get​(int index)
                          throws TemplateModelException
        Retrieves the i-th object from the collection, wrapped as a TemplateModel.
        Specified by:
        get in interface TemplateSequenceModel
        Returns:
        the item at the specified index, or null if the index is out of bounds. Note that a null value 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.
        Throws:
        TemplateModelException - if the index is out of bounds, or the underlying collection is not a List.
      • getSupportsIndexedAccess

        public boolean getSupportsIndexedAccess()
        Tells if get(int) will always fail for this object. As this object implements TemplateSequenceModel, get(int) should always work, but due to a design flaw, for non-List wrapped objects get(int) will always fail. This method exists to ease working this problem around.
        Since:
        2.3.17