Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

OverviewRequires

Platform 4.2+

...

A formatter translates data coming from a data source for display. For example, a formatter might transform the number object 1123.8 into the string “$1,123.80” for display by the user interface. Each binding has a chain of formatters that data passes through.

Declaring formatters is similar to declaring data sources.  The following example shows a formatter:

...

が必要

フォーマッタ

フォー マッタは、データソースから取得したデータを表示用に変換します。たとえば、フォーマッタは数値オブジェクト 1123.8 を、ユーザーインターフェイスによる表示用に文字列 "$1,123.80" に変換できます。各バインディングには、データが経由するフォーマッタのチェーンがあります。

フォーマッタの宣言は、データ ソースの宣言に似ています。次の例に、フォーマッタを示します。

<formatter id=”customers” class=”com.nexaweb.plugin.data.formatter.

...

MessageFormatter” format="There

...

are

...

{0}

...

customers

...

in

...

the

...

database"/>

The following table describes the ways you can define your own formatters: 

Method of Defining FormattersDescription
Supplied tagNexaweb ships with the predefined formatter tag.
Custom tagUse the Nexaweb plug-in architecture to declare a tag that translates data into an appropriate format for the UI to display.

For more information on defining your own formatters, see Creating a Formatter.

...


次の表に、独自のフォーマッタを定義する方法を示します。
フォーマッタの定義メソッド
説明
用意されているタグ
Nexaweb には、定義済みの formatter タグが付属しています。
カスタム タグ
表示する UI 用の適切なフォーマットにデータを変換するタグを宣言するには、Nexaweb のプラグイン アーキテクチャを使用します。

独自のフォーマッタを定義する方法の詳細については、「フォーマッタの作成」を参照してください。

また、Nexaweb には UI での表示用にデータを変換するための次のフォーマッタタグが用意されています。
  • messageFormatter
  • decimalFormatter
  • dateFormatter
  • currencyFormatter
  • stringToDateFormatter
  • formatterChain

For more information on pre-defined formatters, see Supplied Tags.

...

定義済みフォーマッタの詳細については、「用意されているタグ」を参照してください。

メモ: Nexaweb は、すべてのニーズを満たす検証を提供するわけではありません。たとえば、Nexaweb には州の略語、郵便番号、電話番号などのためのフォーマッタは用意されていません。ただし、Nexaweb が提供する formatter タグを使用すれば、これらの機能を実現するフォーマッタを簡単に作成できます。

 

Supplied Formatter Tags

Nexaweb provides the formatter tags described on this page.

formatter Tag

...

Platform 4.2+が必要
用意されているフォーマッタ タグ

ここでは、Nexaweb で用意されているフォーマッタタグについて説明します。

フォーマッタ タグ

com.nexaweb.plugin.data.formatter API

...

The formatter tag includes the following attributes:

AttributeDescription
IDUniquely identifies this formatter using a system wide unique value.
classIdentifies the name of a Java class that implements the formatter interface.

In addition to using the formatter tag to declare your own formatter class, you can also create your own tag that uses different attributes.

...

Use the messageFormatter tag, based on java.text.message format, to specify the pattern and format to use for string messages.

The messageFormatter tag includes the following attributes:

AttributeDescriptionRequired/Optional
idUniquely identifies this messageFormatter using a system wide unique value.Required
formatDefines a valid java.text.MessageFormat pattern string.Required
localeA locale string such as: "en_US"Optional

...

The messageFormatter tag always outputs a java.lang.String object, since the class for this formatter uses the java.text.MessageFormat class.

Input

The following table lists the input types allowed for each format string (since this class uses the java.text.MessageFormat class, the specified format string dictates the input accepted): 

...

を使用して作成したフォーマッタクラスを宣言するには、フォーマッタタグを使用します。

フォーマッタタグには次の属性が含まれています。
属性
説明
ID
システム全体で一意な値を使用し、このフォーマッタを一意に識別します。
class
フォーマッタ インターフェイスを実装する Java クラスの名前を識別します。

フォーマッタ タグを使用して独自のフォーマッタ クラスを宣言することに加えて、異なる属性を使用する独自のタグを作成することもできます。

messageFormatter タグ

文字列メッセージで使用するパターンおよびフォーマットを指定するには、java.text.message フォーマットに基づく messageFormatter タグを使用します。

messageFormatterタグには次の属性が含まれています。
属性
説明
必須/省略可能
id
システム全体で一意な値を使用し、この messageFormatter を一意に識別します。
必須
format
有効な java.text.MessageFormat パターン文字列を定義します。
必須
locale
"en_US" などのロケール文字列です。
省略可能

出力

messageFormatterタグは常に java.lang.String オブジェクトを出力します。これは、このフォーマッタのクラスが java.text.MessageFormat クラスを使用するからです。

入力

次の表に、各フォーマット文字列で許可される入力の型を示します (このクラスでは java.text.MessageFormat クラスを使用するため、指定したフォーマット文字列によって許容される入力が決まります)。
フォーマット文字列
許容される入力
"There are {0} customers"
  • Object
  • Object[] { Object }
  • Object[] { Object, ...}
  • List( Object,... )
  • Vector( Object,... )
  • any primitive array with > 0 elements要素が 1 つ以上の任意のプリミティブ配列
"There are {0,number} customers"
  • Number
  • Object[] { Number }
  • Object[] { Number, ...}
  • List( Number )
  • Vector( Number )
  • any primitive type number array (i.e. int任意のプリミティブ型数値配列 (たとえば、int[]{int,...)
"There are {1} customers"
  • String
  • Object[] { Object,  Object Object }
  • Object[] { Object, Object, ...}
  • List(Object,Object,...)
  • Vector(Object,Object,...)
  • Any primitive array with > 1 elements要素が 2 つ以上の任意のプリミティブ配列
"There are {0, number} customers with {1} cars"
  • Object[] { Number, String }
  • List(Number,String,...)
  • Vector(Number,String,...)

...


メ モ:

...

1.4

...

以降の JVM では、Nexaweb は文字列を数値に解析することが可能な限り、数値が求められるすべての箇所で、getFormatsByArgumentIndex() メソッドを使用して文字列オブジェクトを受け取ります。また、Newxaweb は Long.parseLong(String)

...

またはデフォルトの DateTime インスタンスで文字列を解析することが可能な限り、日付が求められるすべての箇所で、文字列を受け取ります。

JVM 1.3

...

以前の環境では、Nexaweb は引数を求められる型に変換できるとは限りません。これは MessageFormat API で十分な情報が提供されないからです。Nexaweb は、元の引数でフォーマット設定が失敗した場合、引数の変換を試みます。ただし、これがうまくいくのは一部のケース (getFormats() と getFormatsByArgumentIndex() が同じフォーマット配列を返す場合) に限られます。たとえば、"My string with a date: {0,date}, a number {1,number} and some string {2}

...

"というフォーマット文字列の場合、getFormats()

...

getFormatsByArgumentIndex()

...

は同じ結果を返します。

しかし、"My string with some string {2}, a number {1,number} and a date: {0,date}

...

" というフォーマット文字列の場合、これらのメソッドは同じ値を返しません。

いずれのフォーマット文字列でも、getFormatsByArgumentIndex() は同じフォーマットの配列 [DateFormat,NumberFormat,null] (null

...

はフォーマットなし、または String のみを表します) を返します。しかし、getFormats() は最初の例では [DateFormat,NumberFormat,null]

...

、2 番目の例では [null, NumberFormat,DateFormat]

...

をそれぞれ返します。したがって、JVM 1.3

...

以前の環境で最良の結果を得るには、MessageFormatter に適切な引数の型を渡します。

currencyFormatter

...

Available for Nexaweb Java applications only.

...

タグ

数値から通貨文字列を作成するには、java.text.NumberFormat

...

The currentyFormatter tag includes the following attributes:

...

に基づく currentyFormatter タグを使用します。

currentyFormatterタグには次の属性が含まれています。
属性
説明
必須/省略可能
id
システム全体で一意な値を使用し、この currencyFormatter を一意に識別します。
必須
locale
"en_US" などのロケール文字列です。
Optional
省略可能

decimalFormatter

...

タグ

10 進数のフォーマット文字列を作成するには、java.text.DecimalFormat

...

The decimalFormatter tag includes the following attributes:

...

に基づくdecimalFormatterタグを使用します。
decimalFormatterタグには次の属性が含まれます。
属性
説明
必須/省略可能
id
システム全体で一意な値を使用し、この messageFormatter を一意に識別します。
必須
format
"##.0#%" などの 10 進数フォーマット パターンです。
Required
必須
locale
A locale string such as:
"en_US" などのロケール文字列です。
Optional
省略可能

dateFormatter

...

Available for Nexaweb Java applications only.

...

タグ

文字列から日付を作成するには、java.text.DateFormat

...

The dateFormatter tag includes the following attributes:

...

に基づくdateFormatterタグを使用します。

dateFormatterタグには次の属性が含まれます。
属性
説明
必須/省略可能
id
システム全体で一意な値を使用し、この dateFormatter を一意に識別します。
必須
locale
"en_US" などのロケール文字列です。
Optional
省略可能
format
When the input to this formatter is of type Date or Long, the dateFormatter uses this pattern to construct a SimpleDateFormat instance that performs the formatting.
Note:  If you specify a format, Nexaweb ignores the following attributes: dateFormatInstance, dateStyle, timeStyle
Not all locales support SimpleDateFormat, so for full generality, use the attributes specified as ignored instead of format
Optional stringToDateFormatWhen the input to this formatter is a String, the embedded StringToDateFormatter uses this pattern to convert a String into a Date. In general, the following steps take place when the argument to the DateFormatter is a String:The embedded StringToDateFormatter converts the String into a Date using the stringToDateFormat (if specified).  If the stringToDateFormat is specified, it constructs a SimpleDateFormat instance, otherwise Nexaweb uses a default pattern to construct a SimpleDateFormat  instance.  The lenient and timeZone attribute values will be set on this instance.  If parsing using this SimpleDateFormat instance fails, the StringToDateFormatter will also try the following:- Parsing the String as a Long and constructing a Date object using the parsed Long.
- Use RFC1123 format:
このフォーマッタへの入力が Date 型または Long 型の場合、dateFormatter はこのパターンを使用して、フォーマット設定を実行する SimpleDateFormat インスタンスを構築します。
メモ: format を指定した場合、dateFormatInstancedateStyletimeStyleの各属性は無視されます。
すべてのロケールが SimpleDateFormat をサポートするわけではありません。したがって完全な汎用性を実現するには、formatではなく、無視されると指摘した属性を使用します。
省略可能
stringToDateFormat
こ のフォーマッタへの入力が String 型の場合、埋め込みの StringToDateFormatter はこのパターンを使用して String を Date に変換します。一般に、DateFormatter への引数が String の場合、次の手順が実行されます。
AttributeDescriptionRequired/Optional
idUniquely identifies this messageFormatter using a system wide unique value.Required
formatThe specified pattern used to convert the String argument of the format() method into a Date. 
Whether you specify this attribute or not, Nexaweb tries the following steps in order to convert a String into a Date:
  • Parse using a SimpleDateFormat instance constructed either with the specified format or its default format.  The locale, lenient and timeZone attribute values will be set on this instance. 
  • Parsing the String as a Long and constructing a Date object using the parsed Long.
  • Use RFC1123 format
    1. 埋め込みの StringToDateFormatter が stringToDateFormat (指定されている場合) を使用して、String を Date に変換します。stringToDateFormatが指定されている場合は、SimpleDateFormat インスタンスを構築します。それ以外の場合は、デフォルトのパターンを使用して SimpleDateFormat インスタンスが構築されます。このインスタンスでは、属性値 lenient および timeZone が設定されます。この SimpleDateFormat インスタンスを使用した解析が失敗した場合、StringToDateFormatter は次の処理も試みます。

      - String を Long として解析し、解析済みの Long を使用して Date オブジェクトを構築します。
      - RFC1123 フォーマット "EEE, dd MMM yyyy HH:mm:ss z" を使用します。
      - Use RFC1036 format: フォーマット "EEEEEEEEE, dd-MMM-yy HH:mm:ss z"   Use ASCTIME format: を使用します。ASCTIME フォーマット "EEE MMM d HH:mm:ss yyyy" を使用します。

      The default locale for these 3 formatters is Locale.US and the timezone is GMT.

    2. Formats the Date object returned from Step1 using either the format (if specified), or the combination of dateFormatInstance, dateStyle and timeStyle attributes.  The DateFormat instance chosen to do the formatting inherits the values of the locale and timeZone attributes.
     Optional
    stringToDateLocaleThe locale that the embedded StringToDateFormatter uses to parse a string argument.Optional
    dateFormatInstanceSpecifies the form of the date as: date only, time only, or both.
    Values: date | time | date,time.
    Default value: date
    Note: if you use the format attribute, the dateFormatInstance is ignored.  See format for more information.  
    Optional
    dateStyleIf you include date as part of the date format you specify with the dateFormatInstance attribute, use this attribute to specify the length of the formatted date string.
    Values: short | medium | long | full 
    Default: medium
    Note: if you use the format attribute, this attribute is ignored.  See format for more information.  
    Optional
    timeStyleIf you include time in the date format you specify with the dateFormatInstance attribute, use this attribute to specify the length of  the formatted time.
    Values: short | medium | long | full
    Default: medium
    Note: if you use the format attribute, this attribute is ignored.  See format for more information. 
    Optional
    lenientSpecifies whether the StringToDateFormatter performs lenient parsing when the input to the DateFormatter is a String.
    Values: true | false
    Default: true
    Optional
    timeZoneSpecifies the time zone string to use for parsing and/or formatting the inputs to this DateFormatter.
    Values: A time zone string, for example, PST
    If do not use this attribute, TimeZone.getDefault() supplies the default TimeZone.
    Optional

    ...

    Available for Nexaweb Java applications only.

    Use the stringToDateFormatter tag to create dates from a string without any text style formatting.

    The stringToDateFormatter tag includes the following attributes:

    1. これら 3 つのフォーマッタのデフォルトのロケールは Locale.US、タイムゾーンは GMT です。

    2. 手順 1 で返された Date オブジェクトを、format (指定されいてる場合)、または dateFormatInstance、dateStyle、timeStyle の各属性の組み合わせを使用して、フォーマット設定します。フォーマット設定を行うために選択された DateFormat インスタンスは、locale属性と timeZone 属性の値を継承します。
    省略可能
    stringToDateLocale
    埋め込みの StringToDateFormatter が文字列引数を解析するために使用するロケールです。
    省略可能
    dateFormatInstance
    日付のフォーマットを、日付のみ、時間のみ、または日付と時間の両方として指定します。
    値: date、time、または date,time
    デフォルト: date
    メモ: format属性を使用した場合、dateFormatInstanceは無視されます。詳細については、format 属性の説明を参照してください。
    省略可能
    dateStyle
    dateFormatInstance 属性で指定する日付フォーマットの一部として日付を含める場合は、この属性を使用して、フォーマット設定される日付文字列の長さを指定します。
    値: short、medium、long、または full
     
    timeStyledateFormatInstance属性で指定したdata formatにtimeを含む場合、この属性を使用しformatted timeの長さを指定します。
    値: short、medium、long、または full
    デフォルト: medium
    メモ:format属性を使用した場合、この属性は無視されます。詳細については、format 属性の説明を参照して下さい。
     
    LenientDateFormatterへの入力が文字列の場合、StringToDateFormatterがlenient parsingを行うかどうか指定する
    値: true | false
    デフォルト:true
     
    timeZoneこの Dateformatterへの入力をパースおよび/またはフォーマットするために使用する time zone 文字列を指定する
    値:time zone 文字列、例えば PST
    この属性を使用しない場合、TimeZone.getDefault() がデフォルト TimeZone を提供する。
     

    stringToDateFormatter Tag

    Nexaweb Java アプリケーションにのみ利用可能

    stringToDateFormatter タグを使用し、テキストスタイルフォーマットなしに文字列からdateを作成します。
    stringToDateFormatter タグは次の属性を含みます。

    属性説明必須/省略可能
    idシステム全体で一意な値を使用し、このdateFormatter を一意に識別します。必須
    formatformat() method の文字列引数をDateに変換するために使用する特別なパターン。
    この属性を指定するかどうかに拘らず、NexawebはStringをDateに変換するために、次のステップに従います。:
    • 指定したformatもしくはデフォルトフォーマットで構築されたSimpleDateFormat instance を使用しParseする。locale,lenientand timeZone属性値はこのinstanceに設定される。
    • 文字列をLong型としてParseし、parseされたLong型を使用しDate objectを構築する
    • RFC1123 formatを使用: "EEE, dd MMM yyyy HH:mm:ss z" 
    • Use RFC1036 formatformatを使用: "EEEEEEEEE, dd-MMM-yy HH:mm:ss z"
    • Use ASCTIME formatformatを使用: "EEE MMM d HH:mm:ss yyyy"

    The locale for these three default formatters is Locale.US and the timezone is GMT.

    Optional

    これら3つのデフォルトformatterのlocaleはLocaleになる。USとtimezoneはGMT。

    省略可能
    localeA locale string such as: "en_US"などのロケール文字列です。Optional
    lenientWhen the input to the DateFormatter is a String, the lenient attribute specifies whether the parsing performed by the StringToDateFormatter is lenient.  What is lenient?
    ValuesDateFormatterへの入力が文字列の場合、lenient属性はStringToDateFormatter により実施されたparseがlanientかどうかを指定します。Lanientとは?
    : true | false
    Defaultデフォルト: true
    Optional
    timeZoneSpecifies the time zone string to use for parsing and/or formatting the inputs to this StringToDateFormatter.
    Values: A time zone string, for example, PST
    If do not use this attribute, TimeZoneこのDateformatterへの入力をParsingおよび/またはformattingするために使用するtime zone文字列を指定する
    値:time zone文字列、例えばPST
    この属性を使用しない場合、TimeZone.getDefault() supplies the default TimeZone.
    Optional

    ...

    The formatterChain tag defines a chain of formatters where the output of one formatter becomes the input to the next formatter in the chain. You can use this tag anywhere you can use a regular format.  In the following example of a fomatter chain, myStringToDateFormatter, myDateFormatter and myMessageFormatter represent id attributes of the previously defined formatters:

    Code Block
    <formatterChain id="myChain">
       <formatterReference formatter="myStringToDateFormatter/>
       <formatterReference formatter="myDateFormatter" />
       <formatterReference formatter="myMessageFormatter" />
    </formatterChain>
     

    The formatterChain tag uses the ID attribute only.  The ID tag uniquely identifies this messageFormatter using a system wide unique value. The formatterChain tag can use the formatterReference element as a child.

    Back to top

    ...

    Defining Modules to Format Data

    ...

    がデフォルトTimeZoneを提供する。省略可能

     

    Creating a Formatter

    データをフォーマット設定するモジュールの定義
    Nexaweb では、データ バインディング フレームワークの一部として、データを UI での表示用に変換する独自の機能を実装できます。たとえば、データ ソースから返されたカスタム オブジェクトを適切な文字列に変換する独自のフォーマッタを実装することができます。フォーマッタの機能を実装するには、API セクションで定義されている必須インターフェイス (com.nexaweb.plugin.data.formatter.Formatter)

    ...

    Nexaweb ships with the predefined formatter tag. You can use this tag to utilize the interface that you implement by specifying your implementation's class as the class attribute of the formatter tag.

    Formatter tag

    The most basic formatter tag, formatter, simply defines a formatter with its implementing class and its ID.

    AttributeDescriptionRequired/Optional
    idUniquely identifies the formatter; developer should take care to specify a system wide unique value.Required
    classIdentifies the implementation of the formatter.Required

     In addition, developers may elect to create their own formatter tag definitions.

    ...

    を実装する必要があります。

    Nexaweb には、定義済みの formatter タグが付属しています。このタグを使用し、実装するインターフェイスを利用することができます。それには、実装のクラスを formatter タグの class 属性として指定します。

    フォーマッタタグ

    最も基本的なフォーマッタ タグである formatter は、フォーマッタの実装クラスと ID を使用してフォーマッタを定義します。
    属性
    説明
    必須/省略可能
    id
    フォーマッタを一意に識別します。開発者は、システム全体で一意な値を指定するよう注意する必要があります。
    必須
    class
    フォーマッタの実装を識別します。
    必須

    さらに、開発者は独自のフォーマッタ タグ定義を作成することもできます。