Bertie
Bertie

Reputation: 17697

JSF 2 : can EL do something like this?

This works :

<h:outputText value="Active Locale : " /> 
#{view.locale}

But how can i achieve something like this with EL ?

<h:outputText value="Active Locale Decimal Separator : " /> 
#{new DecimalFormat(view.locale).decimalFormatSymbols.groupingSeparator}

Upvotes: 2

Views: 1302

Answers (1)

Arjan Tijms
Arjan Tijms

Reputation: 38163

I wonder what you exactly mean with groupingSeparator?

The standard java.text.DecimalFormat has neither a getGroupingSeparator nor groupingSeparator field or method. So I'm a bit in the dark what you're actually trying to achieve. Would you like to have the _ printed? So if the local is en_uk, that the result is "_"?

Regardless of what you exactly want, you can pretty much do everything by building your own EL functon. In EL it would then look like this:

#{my:someFormatting(view.locale)}

someFormatting is then implemented as a static Java method, which you then assign your own namespace ("my" in this case). Look up a tutorial to help you with this if you need that.

There are also a few standard EL functions available to Facelets. These are the JSTL functions defined in the following namespace:

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

Depending on what you exactly need they may be of some help as well.

Upvotes: 4

Related Questions