[OmniFaces utilities] The
formatNumberDefault()
function formats the given number in the locale-default pattern. This is useful when you want to format numbers in for example the title
attribute of an UI component, or the itemLabel
attribute of select item, or wherever you can't use the <f:convertNumber>
tag. The format locale will be set to the one as obtained by Faces#getLocale()
.Starting with version 2.3 this method was implemented based on the new added, formatNumberDefaultForLocale().
Function:
OmniFaces 2.3 | OmniFaces 2.0 |
See also: Faces#getLocale()
Usage:Let's suppose that we have a map that contains several chemistry numbers, as below:
// in real cases, you may hit a database
private final Map<Float, String> chemistryMap
= Collections.unmodifiableMap(new HashMap<Float, String>() {
{
put(123456f,
"CO2");
put(33337.20546354f,
"HF");
put(314553.78343343f,
"C6H12O6");
put(1229.34332344f,
"C8H18");
put(345987.246f,
"P4O10");
});
public Map<Float, String> getChemistryMap() {
return chemistryMap;
}
Now, we can display a list containing these chemistry numbers. The quantities are formatted via of:formatNumberDefault() as below:
// default locale: en_US
<h:selectOneListbox style="width:100px;">
<f:selectItems value="#{bookBean.chemistryMap.entrySet()}" var="t"
itemLabel="#{of:formatNumberDefault(t.key)}" itemValue="#{t.value}"/>
itemLabel="#{of:formatNumberDefault(t.key)}" itemValue="#{t.value}"/>
</h:selectOneListbox>
Niciun comentariu :
Trimiteți un comentariu