Jsf-convertnumber-tag
提供:Dev Guides
JSF-f:convertNumber
f:convertNumberタグは、文字列値を必要な形式の数に変換するために使用されます。
JSFタグ
<f:convertNumber minFractionDigits = "2"/>
タグ属性
S.No | Attribute & Description |
---|---|
1 |
type 数値(デフォルト)、通貨、またはパーセント |
2 |
pattern java.text.DecimalFormatで定義されているフォーマットパターン |
3 |
maxFractionDigits 小数部の最大桁数 |
4 |
minFractionDigits 小数部の最小桁数 |
5 |
maxIntegerDigits 整数部の最大桁数 |
6 |
minIntegerDigits 整数部の最小桁数 |
7 |
integerOnly 整数部分のみが解析される場合はtrue(デフォルト:false) |
8 |
groupingUsed グループ区切り文字が使用されている場合はtrue(デフォルト:true) |
9 |
locale 解析および書式設定に使用されるプリファレンスのロケール |
10 |
currencyCode 通貨値を変換するときに使用するISO 4217通貨コード |
11 |
currencySymbol 通貨値を変換するときに使用する通貨記号 |
応用例
上記のタグをテストするテストJSFアプリケーションを作成しましょう。
Step | Description |
---|---|
1 | Create a project with a name helloworld under a package com.finddevguides.test as explained in the JSF - First Application chapter. |
2 | Modify home.xhtml as explained below. Keep the rest of the files unchanged. |
3 | Compile and run the application to make sure business logic is working as per the requirements. |
4 | Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver. |
5 | Launch your web application using appropriate URL as explained below in the last step. |
home.xhtml
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"
xmlns:h = "http://java.sun.com/jsf/html"
xmlns:f = "http://java.sun.com/jsf/core">
<h:head>
<title>JSF tutorial</title>
</h:head>
<h:body>
<h2>ConvertNumber Example</h2>
<table border = "1" cellspacing = "2" cellpadding = "2">
<tr>
<th>Parameter</th>
<th>Value Passed</th>
<th>Output</th>
</tr>
<tr>
<td>minFractionDigits = "2"</td>
<td>100.12345</td>
<td>
<h:outputText value = "100.12345" >
<f:convertNumber minFractionDigits = "2"/>
</h:outputText>
</td>
</tr>
<tr>
<td>pattern = "#000.000"</td>
<td>100.12345</td>
<td>
<h:outputText value = "100.12345" >
<f:convertNumber pattern = "#000.000"/>
</h:outputText>
</td>
</tr>
<tr>
<td>currencySymbol = "$"</td>
<td>$100</td>
<td>
<h:outputText value = "$100">
<f:convertNumber currencySymbol = "$" type = "currency"/>
</h:outputText>
</td>
</tr>
<tr>
<td>type = "percent"</td><td>100.12345%</td>
<td>
<h:outputText value = "100.12345%" >
<f:convertNumber type = "percent"/>
</h:outputText>
</td>
</tr>
</table>
</h:body>
</html>
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。