OverviewRequires
...
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.
...
...
...
...
...
...
...
The following table describes the ways you can define your own formatters:
Method of Defining Formatters | Description |
Supplied tag | Nexaweb ships with the predefined formatter tag. |
Custom tag | Use 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
...
ここでは、Nexaweb で用意されているフォーマッタタグについて説明します。
フォーマッタ タグ
com.nexaweb.plugin.data.formatter API
...
The formatter tag includes the following attributes:
Attribute | Description |
ID | Uniquely identifies this formatter using a system wide unique value. |
class | Identifies 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:
Attribute | Description | Required/Optional |
id | Uniquely identifies this messageFormatter using a system wide unique value. | Required |
format | Defines a valid java.text.MessageFormat pattern string. | Required |
locale | A 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" |
|
"There are {0,number} customers" |
|
"There are {1} customers" |
|
"There are {0, number} customers with {1} cars" |
|
...
メ モ:
...
...
...
JVM 1.3
...
...
...
...
しかし、"My string with some string {2}, a number {1,number} and a date: {0,date}
...
いずれのフォーマット文字列でも、getFormatsByArgumentIndex() は同じフォーマットの配列 [DateFormat,NumberFormat,null] (null
...
...
...
...
currencyFormatter
...
Available for Nexaweb Java applications only.
...
数値から通貨文字列を作成するには、java.text.NumberFormat
...
The currentyFormatter tag includes the following attributes:
...
currentyFormatterタグには次の属性が含まれています。
属性 | 説明 | 必須/省略可能 |
id | システム全体で一意な値を使用し、この currencyFormatter を一意に識別します。 | 必須 |
locale | "en_US" などのロケール文字列です。 | Optional 省略可能 |
decimalFormatter
...
10 進数のフォーマット文字列を作成するには、java.text.DecimalFormat
...
The decimalFormatter tag includes the following attributes:
...
属性 | 説明 | 必須/省略可能 |
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タグには次の属性が含まれます。
属性 | 説明 | 必須/省略可能 | |||
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 | stringToDateFormat | When 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 を指定した場合、dateFormatInstance、dateStyle、timeStyleの各属性は無視されます。 すべてのロケールが SimpleDateFormat をサポートするわけではありません。したがって完全な汎用性を実現するには、formatではなく、無視されると指摘した属性を使用します。 | 省略可能 |
stringToDateFormat | こ のフォーマッタへの入力が String 型の場合、埋め込みの StringToDateFormatter はこのパターンを使用して String を Date に変換します。一般に、DateFormatter への引数が String の場合、次の手順が実行されます。 | ||||
Attribute | Description | Required/Optional | |||
id | Uniquely identifies this messageFormatter using a system wide unique value. | Required | |||
format | The 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:
| Optional | |||
stringToDateLocale | The locale that the embedded StringToDateFormatter uses to parse a string argument. | Optional | |||
dateFormatInstance | Specifies 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 | |||
dateStyle | If 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 | |||
timeStyle | If 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 | |||
lenient | Specifies whether the StringToDateFormatter performs lenient parsing when the input to the DateFormatter is a String. Values: true | false Default: true | Optional | |||
timeZone | Specifies 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:
| 省略可能 | |
stringToDateLocale | 埋め込みの StringToDateFormatter が文字列引数を解析するために使用するロケールです。 | 省略可能 |
dateFormatInstance | 日付のフォーマットを、日付のみ、時間のみ、または日付と時間の両方として指定します。 値: date、time、または date,time デフォルト: date メモ: format属性を使用した場合、dateFormatInstanceは無視されます。詳細については、format 属性の説明を参照してください。 | 省略可能 |
dateStyle | dateFormatInstance 属性で指定する日付フォーマットの一部として日付を含める場合は、この属性を使用して、フォーマット設定される日付文字列の長さを指定します。 値: short、medium、long、または full | |
timeStyle | dateFormatInstance属性で指定したdata formatにtimeを含む場合、この属性を使用しformatted timeの長さを指定します。 値: short、medium、long、または full デフォルト: medium メモ:format属性を使用した場合、この属性は無視されます。詳細については、format 属性の説明を参照して下さい。 | |
Lenient | DateFormatterへの入力が文字列の場合、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 を一意に識別します。 | 必須 |
format | format() method の文字列引数をDateに変換するために使用する特別なパターン。 この属性を指定するかどうかに拘らず、NexawebはStringをDateに変換するために、次のステップに従います。:
The locale for these three default formatters is Locale.US and the timezone is GMT. Optionalこれら3つのデフォルトformatterのlocaleはLocaleになる。USとtimezoneはGMT。 | 省略可能 |
locale | A 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 |
timeZone | Specifies 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.
...
Defining Modules to Format Data
...
がデフォルトTimeZoneを提供する。 | 省略可能 |
Creating a 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.
Attribute | Description | Required/Optional |
id | Uniquely identifies the formatter; developer should take care to specify a system wide unique value. | Required |
class | Identifies 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 | フォーマッタの実装を識別します。 | 必須 |
さらに、開発者は独自のフォーマッタ タグ定義を作成することもできます。