Provides the default object for formatting the display of model objects in Velocity templates and JSP pages.
For Velocity templates a Format object is added to the Velocity Context using the name "
format", while for JSP pages an instance is added as a request attribute using the same key.
For example the following Page code adds a date to the model:
public void onGet() { Date date = order.deliveryDate(); addModel("deliveryDate", date); }
In the page template we use the format object:
Delivery date: $format.date($deliveryDate, "dd MMM yyyy")
Which renders the output as:
Delivery date: 21 Jan 2004 |
The custom format class can be defined in the "click.xml" configuration file using the syntax:
<format classname="com.mycorp.utils.MyFormat"/>
After a Page is created its
format property is set. The ClickServlet will then add this property to the Velocity Context.
When subclassing Format ensure it is light weight object, as a new format object will be created for every new Page.
@see PageImports