Skip to content

Using Globalization Custom Tags

thofrey edited this page Apr 1, 2014 · 12 revisions

Table of Contents

  1. Introduction
  2. The Tags

Introduction

Create globalized application easier and faster in your view layer with the introduction of the 7 custom tags in the "view" custom tag library that ships with Mach-II 1.9+.

You can use the Globalization custom tags by just importing the Mach-II view tag library at the top of your .cfm view page in your application.

    <cfimport prefix="view" taglib="/MachII/customtags/view/" />

The Tags

Common/Shared Attributes in All Tags Below

  • var - optional - string -The variable to assign the output of the formatter to. Defaults to outputting to screen and not to a variable. Be sure to use a fully qualified variables (i.e. variables.something).
  • display - optional - boolean - Outputs to screen. Defaults to true.
  • locale - optional - string - The locale to use. Defaults to the current request locale.
  • defaultValue - optional - string - The value to use if the length of value equals 0.

Format Number

Formats a number using an optional pattern and rounding mode.

    <view:formatnumber
        value="12345.96"
        pattern=__,___.__"
        roundingMode="UP|DOWN|CEILING|FLOOR|HALF_UP|HALF_DOWN|HALF_EVEN|UNNECESSARY" />

Also allows to nest the value between a start and closing tag:

    <view:formatnumber>12345.96</view:formatnumber>

Attributes

  • value - required - The value to format.
  • pattern - optional - string - The pattern to use in the formatter. Defaults to the default pattern for the current or passed locale.
  • roundingMode - optional - valid list item - The rounding mode to use if the input value needs rounding based on the pattern. See this documentation for more information java.math.RoundingMode. Defaults to NO rounding.

Using Patterns

The optional pattern attribute takes a the pattern for formatting otherwise it will default the Java pattern for current locale. We use the Java Decimal Pattern Format for all patterns except we use _ (underscored) instead of # (pound sign) because of the special meaning of pounds in CFML.

Format Currency

Formats currency.

    <view:formatcurrency value="12345.96" />

Also allows to nest the value between a start and closing tag:

    <view:formatcurrency>12345.96</view:formatcurrency>

Attributes

  • value - required - The value to format.

Format Percent

Formats a percentage.

    <view:formatpercent value="12345.96" />

Also allows to nest the value between a start and closing tag:

    <view:formatpercent>12345.96</view:formatpercent>

Attributes

  • value - required - The value to format.

Format Datetime

Formats a date/time.

    <view:formatdatetime value="#variables.someDatetime"
        pattern="short|medium|long|full|custom pattern" />

Also allows to nest the value between a start and closing tag:

    <view:formatdatetime>ts{2012-07-07 15:31:00}</view:formatdatetime>

Attributes

  • value - required - date - The value to format.
  • pattern - optional - lists of values or custom patterns - The pattern to use for the formatting - takes a list or array (first position date, second position time). Defaults to the SHORT for the current locale. Custom formats follow the Java SimpleDateFormat class.

Examples

Same pattern for both date and time:

    <view:formatdatetime value="#variables.someDatetime" pattern="full" />

Different patterns for both date (full) and time (short):

    <view:formatdatetime value="#variables.someDatetime" pattern="full,short" />

Or using arrays:

    <view:formatdatetime value="#variables.someDatetime" pattern="#['full', 'short']#" />

Format Date

Formats a date.

    <view:formatdate value="#variables.someDatetime"
        pattern="short|medium|long|full|custom pattern" />`

Also allows to nest the value between a start and closing tag:

    <view:formatdate>ts{2012-07-07 15:31:00}</view:formatdate>

Attributes

  • value - required - date - The value to format.
  • pattern - optional - list of value or custom pattern - The pattern to use for the formatting. Defaults to the default pattern for the current locale. Custom formats follow the Java SimpleDateFormat class.

Format Time

Formats a time.

    <view:formattime value="#variables.someDatetime"
        pattern="short|medium|long|full|custom pattern" />`

Also allows to nest the value between a start and closing tag:

    <view:formattime>ts{2012-07-07 15:31:00}</view:formattime>

Attributes

  • value - required - date - The value to format.
  • pattern - optional - list of value or custom pattern - The pattern to use for the formatting. Defaults to the default pattern for the current locale. Custom formats follow the Java SimpleDateFormat class.
Clone this wiki locally