• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • scripts
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
 - 
  • converter
  • enableRestorableView
  • ignoreValidationFailed
  • importConstants
  • importFunctions
  • massAttribute
  • methodParam
  • skipValidators
  • tagAttribute
  • validator
  • viewParamValidationFailed

Available since OmniFaces 1.0

The <o:converter> is a taghandler that extends the standard <f:converter> tag family with support for deferred value expressions in all attributes. In other words, the converter attributes are not evaluated anymore on a per view build time basis, but just on every access like as with UI components and bean properties. This has among others the advantage that they can be evaluated on a per-iteration basis inside an iterating component, and that they can be set on a custom converter without needing to explicitly register it in a tagfile.

Usage

When you specify for example the standard <f:convertDateTime> by converterId="javax.faces.DateTime", then you'll be able to use all its attributes such as pattern and locale as per its documentation, but then with the possibility to supply deferred value expressions.

<o:converter converterId="javax.faces.DateTime" pattern="#{item.pattern}" locale="#{item.locale}" />

The converter ID of all standard JSF converters can be found in their javadocs. First go to the javadoc of the class of interest, then go to CONVERTER_ID in its field summary and finally click the Constant Field Values link to see the value.

Demo

In the below demo, it was the intent to use <f:convertDateTime> as follows:

 <f:convertDateTime type="both" dateStyle="full" timeStyle="full" locale="#{locale}" />

But this wouldn't even run, it will throw the following exception because the #{locale} isn't available during view build time (for a background explanation, check this Stack Overflow answer).

 javax.faces.view.facelets.TagAttributeException: /taghandlers/converter @62,92 
 locale="" Attribute did not evaluate to a String or Locale: null
     at com.sun.faces.facelets.tag.jsf.ComponentSupport.getLocale(ComponentSupport.java:297)
     at com.sun.faces.facelets.tag.jsf.core.ConvertDateTimeHandler.setAttributes(ConvertDateTimeHandler.java:127)
     at com.sun.faces.facelets.tag.jsf.ConverterTagHandlerDelegateImpl.applyAttachedObject(ConverterTagHandlerDelegateImpl.java:130)
		

It works as intuitively expected with the <o:converter> as it allows a render time evaluation of attributes.

For another related use case, checkout the <o:validator> showcase page.

Demo
Language Full date time pattern
English Wednesday, April 26, 2017 8:04:22 AM GMT
Spanish miércoles 26 de abril de 2017 08H04' GMT
French mercredi 26 avril 2017 08 h 04 GMT
German Mittwoch, 26. April 2017 08:04 Uhr GMT
Dutch woensdag 26 april 2017 8:04:22 uur GMT
Arabic 26 أبريل, 2017 GMT 08:04:22 ص
Hebrew 08:04:22 GMT יום רביעי 26 אפריל 2017
Chinese 2017年4月26日 星期三 上午08时04分22秒 GMT
Demo source code
<h:dataTable value="#{converterBean.locales}" var="locale">
    <h:column>
        <f:facet name="header">Language</f:facet>
        #{locale.displayLanguage}
    </h:column>
    <h:column>
        <f:facet name="header">Full date time pattern</f:facet>
        <h:outputText value="#{now}">
            <o:converter converterId="javax.faces.DateTime" type="both" dateStyle="full" timeStyle="full" locale="#{locale}" />
        </h:outputText>
    </h:column>
</h:dataTable>
Documentation & Sources

VDL documentation

API documentation

Java source code