freemarker.ext.misc
Class AsString

java.lang.Object
  |
  +--freemarker.ext.misc.AsString
All Implemented Interfaces:
TemplateMethodModel2, TemplateModel

public final class AsString
extends java.lang.Object
implements TemplateMethodModel2

Performs a type conversion from a number model to a String model. This is useful when we need to perform String concatenation on two numbers, or when we only want a number from a multimodel.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "asString", freemarker.ext.misc.AsString.getInstance() );

 ...
 

From your FM-Classic template:

 <assign var1 = 5>
 <assign var2 = 3>
 <assign var3 = asString( var1 ) + asString( var2 )>
 <p>The concatenation of ${var1} and ${var2} is: ${var3}</p>

 ...
 

Note:
AsString is a singleton instance. Use the getInstance() method to retrieve instances of this model.

Since:
1.8
Version:
$Id: AsString.java,v 1.5 2003/11/17 13:06:24 run2000 Exp $
Author:
Nicholas Cull

Method Summary
 TemplateModel exec(java.util.List arguments)
          Perform a number to string conversion on the given template model.
static AsString getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is this model empty?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static AsString getInstance()
Retrieve a singleton instance of this class. Since there is no state information held between calls, there is only a need for one instance.
Returns:
an instance of this AsString class

exec

public TemplateModel exec(java.util.List arguments)
                   throws TemplateModelException
Perform a number to string conversion on the given template model.
Specified by:
exec in interface TemplateMethodModel2
Parameters:
arguments - a List of exactly one template model to be converted
Returns:
a new TemplateScalarModel of the String value
Throws:
TemplateModelException - More than one argument is supplied, or the model is neither a number nor a string model.

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is this model empty?
Specified by:
isEmpty in interface TemplateModel
Returns:
false, to indicate the model is non-empty