<f:convertDateTime> converts only the value attribute, not the other attributes. In this particular case, it is best to create a custom EL function for this.
First, create the final class using the public static method, which takes the necessary arguments and delegates in the JSF DateTimeConverter (the package / class / method name is optional):
package com.example.util; import java.util.Date; import java.util.TimeZone; import javax.faces.component.UIOutput; import javax.faces.context.FacesContext; import javax.faces.convert.DateTimeConverter; public final class Functions { private Functions() {
Define it as facelet-taglib in /META-INF/functions.taglib.xml (the file name is free of choice):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://example.com/util/functions</namespace> <function> <function-name>convertDateTime</function-name> <function-class>com.example.util.Functions</function-class> <function-signature>java.lang.String convertDateTime(java.util.Date, java.lang.String, java.lang.String, java.lang.String, java.util.TimeZone)</function-signature> </function> </facelet-taglib>
(note: for Facelets 2.x you need XSD instead of DTD, for an example see this answer )
Register it as the new taglib in /WEB-INF/web.xml :
<context-param> <param-name>facelets.LIBRARIES</param-name> <param-value>/META-INF/functions.taglib.xml</param-value> </context-param>
(note: if you have already defined facelets.LIBRARIES , then you can just add a new path processed by processing, for Facelets 2.x you need javax.faces.FACELETS_LIBRARIES context parameter)
Declare it in the Facelets XHTML file as the new XML namespace:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:uf="http://example.com/util/functions" ... >
Finally, you can use it for its intended purpose:
<h:outputText value="foo" title="#{uf:convertDateTime(bean.date, 'both', 'medium', 'short', bean.timeZone)}" />
If necessary, you can specify the type and styles in the function and give the method a different name that indicates these default values.
If you use the JSF OmniFaces utility library , you can also use it #{of:formatDate()} .