Tuesday, October 20, 2009

The I18N Tags






















 Print  
 E-Mail
 
 Add
Note    Add
Bookmark
   














JSTL:
JSP Standard Tag Library Kick Start
By
Jeff Heaton

Table
of Contents
Appendix A.  JSTL
Reference









The I18N Tags


Java contains extensive support for
internationalization, or I18N. Multilingual programming is
supported by allowing strings to be stored in
language-specific Java resource bundles. These bundles can be
exchanged as language needs vary. JSTL also includes
formatting tags that allow you to properly format numbers,
dates, and currencies for specific locales.


The <fmt:bundle>
Tag


The <fmt:bundle> tag is used
to load the specified bundle and use it as the default bundle
for any <fmt:message> tags that fall inside the
<fmt:bundle> block. If you want to load a
bundle to a scoped variable, you should use the
<fmt:setBundle> tag.

<fmt:bundle basename="basename" prefix="prefix"/>
</fmt:setBundle>

The <fmt:bundle> tag has the
following attributes:


















class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


basename


Y


Specifies the base name of the resource
bundle that is to be loaded.


prefix


N


Specifies a prefix that will be added
to every key attribute specified in the
<fmt:message>
tags.


The <fmt:formatDate>
Tag


The <fmt:formatDate> tag is
used to format dates in a variety of standard forms.

<fmt:formatDate [value="date"]
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[var="varName"]
[scope="{page|request|session|application}"]/>

The <fmt:formatDate> tag uses
the following attributes:










































class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


dateStyle


N


A predefined formatting style for
dates. Applied only when formatting a date, or both a
date and time (that is, if type is missing or
is equal to date or both); ignored
otherwise.


pattern


N


A custom formatting style for dates and
times.


scope


N


The scope of var; the default
is page.


timeStyle


N


A predefined formatting style for
times. Applied only when formatting a time, or both a
date and time (that is, if type is equal to
time or both); ignored
otherwise.


timeZone


N


Specifies the time zone in which to
represent the formatted time.


type


N


Specifies whether only the time, the
date, or both the time and date components of the given
date are to be formatted. The default is
date.


value


Y


The date and/or time that should be
formatted.


var


N


The name of the exported scoped
attribute that stores the formatted result as a
String.


The
<fmt:formatNumber> Tag


The <fmt:formatNumber> tag is
used to format dates in a variety of standard forms.

// Syntax 1: Without a body
<fmt:formatNumber value="numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[currencyCode="currencyCode"]
[currencySymbol="currencySymbol"]
[groupingUsed="{true|false}"]
[maxIntegerDigits="maxIntegerDigits"]
[minIntegerDigits="minIntegerDigits"]
[maxFractionDigits="maxFractionDigits"]
[minFractionDigits="minFractionDigits"]
[var="varName"]
[scope="{page|request|session|application}"]/>
// Syntax 2: With a body to specify the numeric value to be
formatted
<fmt:formatNumber [type="{number|currency|percent}"]
[pattern="customPattern"]
[currencyCode="currencyCode"]
[currencySymbol="currencySymbol"]
[groupingUsed="{true|false}"]
[maxIntegerDigits="maxIntegerDigits"]
[minIntegerDigits="minIntegerDigits"]
[maxFractionDigits="maxFractionDigits"]
[minFractionDigits="minFractionDigits"]
[var="varName"]
[scope="{page|request|session|application}"]>
numeric value to be formatted
</fmt:formatNumber>

The <fmt:formatNumber> tag
uses the following attributes:


























































class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


currencyCode


N


String ISO 4217 currency code. Applied
only when formatting currencies (that is, if
type is equal to currency); ignored
otherwise.


currencySymbol


N


String Currency symbol. Applied only
when formatting currencies (that is, if type is
equal to currency); ignored
otherwise.


groupingUsed


N


Specifies whether the formatted output
will contain any grouping separators. The default is
true.


maxFractionDigits


N


The maximum number of digits in the
fractional portion of the formatted output.


maxIntegerDigits


N


The maximum number of digits in the
integer portion of the formatted output.


minFractionDigits


N


The minimum number of digits in the
fractional portion of the formatted output.


minIntegerDigits


N


The minimum number of digits in the
integer portion of the formatted output.


pattern


N


String Custom formatting pattern.
Applied only when formatting numbers (that is, if
type is missing or is equal to
number); ignored otherwise.


scope


N


The scope of var. The default
is page.


type


N


Specifies whether the value is to be
formatted as number, currency, or
percentage. The default is
number.


value


N


The String or Number Numeric value to
be formatted.


var


N


The name of the exported scoped
attribute that stores the formatted result as a
String.


The <fmt:message>
Tag


The <fmt:message> tag is used
to insert multilingual text into JSP pages. This tag
references strings stored in resource bundles. If the
<fmt:message> tag is inside a
<fmt:bundle> block, then
<fmt:message> will use
<fmt:bundle> to determine which resource bundle
to use. If the <fmt:message> tag is outside a
<fmt:bundle> block, then
resourceBundle must be scoped variable obtained from
a previous call to <fmt:setBundle>. It can also
use a configured localization context.

// Syntax 1: Without body content
<fmt:message key="messageKey"
[bundle="resourceBundle"]
[var="varName"]
[scope="{page|request|session|application}"]/>
// Syntax 2: With a body to specify message parameters
<fmt:message key="messageKey"
[bundle="resourceBundle"]
[var="varName"]
[scope="{page|request|session|application}"]>
<fmt:param> subtags
</fmt:message>
// Syntax 3: With a body to specify key and optional message
parameters
<fmt:message [bundle="resourceBundle"]
[var="varName"]
[scope="{page|request|session|application}"]>
key
optional <fmt:param> subtags
</fmt:message>

The <fmt:message> tag has the
following attributes:


























class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


bundle


N


Specifies the resource bundle that is
to be used. If this tag occurs from within a
<fmt:bundle> tag, then no bundle needs to
be specified.


key


N


Specifies the lookup key that
identifies the desired string inside the
bundle.


scope


N


Specifies the scope of the scoped
variable referenced by the var attribute. If
the var attribute is not needed, then the
scope attribute should not be specified. The
default is page.


var


N


Specifies a scoped variable that will
receive the value of the string that is being looked up.
If no var attribute is specified, then the
output will be written to the
page.


The <fmt:param>
Tag


The <fmt:param> tag is used to
specify parameters that will fill in the
<fmt:message> string.

// Syntax 1: Value specified via attribute value
<fmt:param value="messageParameter"/>
// Syntax 2: Value specified via body content
<fmt:param>
body content
</fmt:param>

The <fmt:param> tag has one
attribute. Only 10 parameters may be specified.














class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


value


N


Specifies the value that is to be
inserted for the
parameter.


The <fmt:parseDate>
Tag


The <fmt:parseDate> tag is
used to transform a string into a Java date.

// Syntax 1: Without a body
<fmt:parseDate value="dateString"
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[parseLocale="parseLocale"]
[var="varName"]
[scope="{page|request|session|application}"]/>
// Syntax 2: With a body to specify the date value to be parsed
<fmt:parseDate [type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[parseLocale="parseLocale"]
[var="varName"]
[scope="{page|request|session|application}"]>
date value to be parsed
</fmt:parseDate>

The <fmt:parseDate> tag has
the following attributes:










































class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


dateStyle


N


The style for the date. Should be
default, short, long,
medium, or full. The default is
default. This attribute uses
DateFormat semantics.


parseLocale


N


Specifies the locale that should be
used. This attribute should be of type String
or java.util.Locale.


pattern


N


Specifies how the date is to be parsed
using a pattern.


timeStyle


N


The style for the time. Should be
default, short, long,
medium, or full. The default is
default.


timeZone


N


The zone that the parsed time is from.
This value should be of type String or
java.util.TimeZone.


type


N


The type of date to parse. Should be
time, date, or both. The
default is date.


value


N


The string to be parsed.


var


N


The name of the exported scoped
attribute that stores the parsed result (of type
java.lang.Number).


The
<fmt:parseNumber> Tag


The <fmt:parseNumber> tag is
used to parse strings into numeric values. If the value
specified cannot be transformed into a numeric value, then an
exception will be thrown.

// Syntax 1: Without a body
<fmt:parseNumber value="numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[parseLocale="parseLocale"]
[integerOnly="{true|false}"]
[var="varName"]
[scope="{page|request|session|application}"]/>
// Syntax 2: With a body to specify the numeric value to be parsed
<fmt:parseNumber [type="{number|currency|percent}"]
[pattern="customPattern"]
[parseLocale="parseLocale"]
[integerOnly="{true|false}"]
[var="varName"]
[scope="{page|request|session|application}"]>
numeric value to be parsed
</fmt:parseNumber>

The <fmt:parseNumber> tag has
the following attributes:






































class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


integerOnly


N


Specifies whether just the integer
portion of the given value should be parsed. Defaults to
false.


parseLocale


N


The locale whose default formatting
pattern (for numbers, currencies, or percentages,
respectively) is to be used during the parse operation,
or to which the pattern specified via the
pattern attribute (if present) is
applied.


pattern


N


Custom formatting pattern that
determines how the string in the value
attribute is to be parsed. Applied only when parsing
numbers (that is, if type is missing or is
equal to number); ignored otherwise.


scope


N


The scope of var. Defaults to
page.


type


N


Specifies whether the string in the
value attribute should be parsed as
number, currency, or
percentage. Defaults to
number.


value


N


The string to be parsed.


var


N


The name of the exported scoped
attribute that stores the parsed result (of type
java.lang.Number).


The
<fmt:requestEncoding> Tag


The <fmt:requestEncoding> tag
is used to specify the encoding method used in the form that
posted to the current page. This allows JSTL to properly
determine the parameters that were posted to the current
page.

<fmt:requestEncoding [value="charsetName"]/>

The <fmt:requestEncoding> tag
has one attribute:














class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


value


N


The name of the character encoding to
be applied when decoding request
parameters.


The <fmt:setBundle>
Tag


The <fmt:setBundle> tag is
used to load a Java resource bundle into a JSTL scoped
variable. The scoped variable can then be provided to future
calls to the <fmt:message> tag.

<fmt:setBundle basename="basename"
[var="varName"]
[scope="{page|request|session|application}"]>

The <fmt:setBundle> tag
contains the following attributes:






















class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


basename


Y


Specifies the base name of the resource
bundle that is to be loaded in the form or fully
qualified classname.


scope


N


Specifies the scope of the variable
that is contained in the var attribute.
Defaults to page.


var


N


Specifies a scoped variable that will
hold the newly instantiated resource
bundle.


The <fmt:setLocale>
Tag


The <fmt:setLocale> tag is
used to specify the current locale for the Web
application.

<fmt:setLocale value="locale"
[variant="variant"]
[scope="{page|request|session|application}"]/>

The <fmt:setLocale> tag has
the following attributes:






















class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


value


Y


The locale species a two-part code that
represents the ISO-639 language code and an ISO-3166
country code (for example,en-US).


scope


N


Specifies the scope of this locale
setting. The default is page.


variant


N


Specifies a vendor- or browser-specific
variant of the language referenced by value.
For more information, refer to the
java.util.Locale
JavaDocs.


The
<fmt:setTimeZone> Tag


The <fmt:setTimeZone> tag is
used to specify the time zone for the Web application.

<fmt:setTimeZone value="timeZone"
[var="varName"]
[scope="{page|request|session|application}"]

The <fmt:setTimeZone> tag has
the following attributes:






















class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


scope


N


Specifies the scope of scoped variable
referenced by var. The default is
page.


value


Y


Specifies the time zone that should be
used by the tags enclosed in the body of this tag. See
the java.util.TimeZone JavaDoc for formats.


var


N


Specifies the scoped variable that is
to receive the time
zone.


The <fmt:timeZone>
Tag


The <fmt:timeZone> tag is used
to specify a time zone that will be used by all tags inside
the body of the <fmt:timeZone> tag. The
<fmt:timeZone> tag has one attribute:














class=docEmphStrong>Attribute


class=docEmphStrong>Required


class=docEmphStrong>Purpose


value


Y


Specifies the time zone that should be
used by the tags enclosed in the body of this tag. See
the java.util.TimeZone JavaDoc for
formats.











     Print  
     E-Mail
     
     Add
    Note    Add
    Bookmark
       




    Top

    [0672324504/app01lev1sec2]






     
     

    No comments:

    Post a Comment