• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
 - 
  • ImplicitNumberConverter
  • ListConverter
  • ListIndexConverter
  • SelectItemsConverter
  • SelectItemsIndexConverter
  • ToCollectionConverter
  • ToLowerCaseConverter
  • ToUpperCaseConverter
  • TrimConverter
  • ValueChangeConverter

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>
Demo

Try entering a price of 12.34 with or without $ symbol.

Using <f:convertNumber>

Using ImplicitNumberConverter

Demo source code
<p>Try entering a price of <code>12.34</code> with or without <code>$</code> symbol.</p>

<h:form>
    <h2>Using &lt;f:convertNumber&gt;</h2>
    <h:panelGrid columns="3">
        <o:outputLabel for="price" value="Price&#xA0;$" />
        <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&#xA0;$" />
        <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>