-
Available since OmniFaces 3.0
This converter won't output the percent or currency symbols, that's up to the UI. This converter will implicitly infer percent or currency symbols on submitted value when absent, just to prevent an unnecessary conversion error.
Usage
This converter is available by converter ID omnifaces.ImplicitNumberConverter
. Just specify it as <o:converter>
nested in the component referring the Number
property. For example:
<span class="currency">
<span class="symbol">$</span>
<h:inputText value="#{bean.price}">
<o:converter converterId="omnifaces.ImplicitNumberConverter" type="currency" currencySymbol="$" />
</h:inputText>
</span>
Since OmniFaces 4.5 it's also available by <o:implicitNumberConverter>
tag.
<span class="currency">
<span class="symbol">$</span>
<h:inputText value="#{bean.price}">
<o:implicitNumberConverter type="currency" currencySymbol="$" />
</h:inputText>
</span>
Demo
Try entering a price of 12.34
with or without $
symbol.
Demo source code
<p>Try entering a price of <code>12.34</code> with or without <code>$</code> symbol.</p>
<h:form>
<h2>Using <f:convertNumber></h2>
<h:panelGrid columns="3">
<o:outputLabel for="price" value="Price $" />
<h:inputText id="price" required="true">
<f:convertNumber type="currency" currencySymbol="$" />
</h:inputText>
<h:message for="price" />
<h:panelGroup />
<h:commandButton value="submit">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
</h:panelGrid>
</h:form>
<h:form>
<h2>Using ImplicitNumberConverter</h2>
<h:panelGrid columns="3">
<o:outputLabel for="price" value="Price $" />
<h:inputText id="price" required="true">
<o:converter converterId="omnifaces.ImplicitNumberConverter" type="currency" currencySymbol="$" />
</h:inputText>
<h:message for="price" />
<h:panelGroup />
<h:commandButton value="submit">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
</h:panelGrid>
</h:form>
Documentation & Sources