JSF Showcase

f:convertNumber

The f:convertNumber Facelet tag exposes the functionality of a NumberConverter inside Facelet views.

General Usage

The type attribute can be set to "currency", "number", or "percent" in order to convert different types of numbers.


3.14

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html">

	<h:form>
		<h:inputText id="number" converterMessage="#{i18n['converter-message']}"
			value="#{converterModelBean.number}">
			<f:convertNumber maxFractionDigits="2" />
		</h:inputText>
		<br />
		<h:message for="number" />
		<hr />
		<h:commandButton value="#{i18n['submit']}">
			 <f:ajax render="@form" execute="@form" />
		</h:commandButton>
		<h:outputText id="modelValue" value="#{converterModelBean.number}">
			<f:convertNumber maxFractionDigits="2" />
		</h:outputText>
	</h:form>

</ui:composition>
@ManagedBean
@RequestScoped
public class ConverterModelBean {

	@ManagedProperty(value = "#{countryService}")
	private CountryService countryService;

	// Private properties
	private Country country;
	private double number = 3.141516;

	public Country getCountry() {
		return country;
	}

	public CountryService getCountryService() {
		return countryService;
	}

	public double getNumber() {
		return number;
	}

	@PostConstruct
	public void postConstruct() {
		this.country = countryService.getAllCountries().get(0);
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public void setCountryService(CountryService countryService) {
		this.countryService = countryService;
	}

	public void setNumber(double number) {
		this.number = number;
	}

}
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14