|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectfreemarker.ext.misc.CollectionSize
public final class CollectionSize
Determines the size of the underlying Collection or
Map object given a TemplateObjectModel. Does this
by calling the getAsObject method. If the object is of the
expected type, the size is returned as a FastNumber. Otherwise,
a TemplateModelException is thrown.
Usage:
From java:
TemplateModelRoot root = new SimpleHash(); root.put( "size", freemarker.ext.misc.CollectionSize.getInstance() ); ...
From your FM-Classic template:
<assign list1 = [ "test1", "test2", "test3" ]>
<assign listSize = size( list1 )>
<p>The size of list1 is: ${listSize}</p>
...
Note:
CollectionSize is a singleton instance. Use the
getInstance() method to retrieve instances of this model.
| Method Summary | |
|---|---|
TemplateModel |
exec(java.util.List<TemplateModel> arguments)
Retrieves the size of the given Collection or Map. |
static CollectionSize |
getInstance()
Retrieve a singleton instance of this class. |
boolean |
isEmpty()
Is the object empty? |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static CollectionSize getInstance()
CollectionSize class
public boolean isEmpty()
throws TemplateModelException
isEmpty in interface TemplateModelfalse, since the method is never empty
TemplateModelException
public TemplateModel exec(java.util.List<TemplateModel> arguments)
throws TemplateModelException
Retrieves the size of the given Collection or Map. Performs an
unwrapping by calling getAsObject, then calls the
size method of the underlying object.
exec in interface TemplateMethodModel2arguments - a List containing a
TemplateObjectMode as its single item
TemplateNumberModel
TemplateModelException - the size could not be determined
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||