HTML and CSS Reference
In-Depth Information
In order to convert the input String to birthDate attribute with the "dd-MM-yyyy" format, you can attach the
<f:convertDateTime> to EditableValueHolder component as follows:
<h:outputText value="Date of birth:"/>
<h:inputText id="birthDate"
value="#{testBean.birthDate}"
required="true">
<f:convertDateTime pattern="dd-MM-yyyy"/>
</h:inputText>
If the user enters a value in the birthDate field that cannot be converted to a Date object with the "dd-MM-yyyy"
format, a conversion error message will be displayed. Listing 3-2 shows an example of <f:convertNumber> converter
which converts the input String to a Java Number object. In addition, it has many formatting capabilities. Assume
that we have the someNumber (of type Double) attribute of TestBean managed bean #{testBean.someNumber} ,
and we want to format it on the number format ###,###.###; this can be achieved using the pattern attribute of
<f:convertNumber> as follows:
<h:outputText value="#{testBean.someNumber}">
<f:convertNumber pattern="###,###.###"/>
</h:outputText>
Assuming that the #{testBean.someNumber} is evaluated to 123456.124 (for example), it will be displayed
as 123,456.124 .
Not You can read more about the Java NumberFormat at
http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html
If we want to display only two fraction digits of the #{testBean.someNumber} number, we can use the
maxFractionDigits attribute of the <f:convertNumber> tag as follows:
<h:outputText value="#{testBean.someNumber}">
<f:convertNumber maxFractionDigits="2"/>
</h:outputText>
If the #{testBean.someNumber} is evaluated to 123456.124 for example, it will be displayed as 123,456.12 .
Using both the currencyCode and the type (="currency") attributes of the <f:convertNumber> , we can format
the number in currency format as follows:
<h:outputText value="#{testBean.someNumber}">
<f:convertNumber currencyCode="EGP" type="currency"/>
</h:outputText>
If the #{testBean.someNumber} is evaluated to 2000 for example, it will be displayed as EGP2,000.00 .
Not the currency codes are defined in ISo 4217. You can get the full list of currency codes from
http://en.wikipedia.org/wiki/ISO_4217
 
Search WWH ::




Custom Search