Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:03:31+00:00 2026-05-25T22:03:31+00:00

Is it possible in JSF to convert a date value and put it in

  • 0

Is it possible in JSF to convert a date value and put it in “title” attribute? In a similar question, JSF Convert dates for title attribute, there was an answer, that it can be done with JSTL’s fmt:formatDate, but not in repeating components, such as UIData. I need to do it inside a table (extended HtmlDataTable).

For example, the following code correctly displays the date as text value, but not in the title attribute:

<h:outputText class="yui-tip" title="#{task[col.attributeName]}" value="#{task[col.attributeName]}">
    <f:convertDateTime type="both" dateStyle="medium" timeStyle="short"   timeZone="#{userProfileBean.clientTimeZone}" />
</h:outputText>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:03:31+00:00Added an answer on May 25, 2026 at 10:03 pm

    The <f:convertDateTime> only converts the value attribute, not other attributes. In this particular case, your best bet is to create a custom EL function for that.

    First create a final class with a public static method which takes the necessary arguments and delegates to the JSF DateTimeConverter (package/class/method name is free to your choice):

    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() {
            // Hide constructor.
        }
    
        public static String convertDateTime(Date date, String type, String dateStyle, String timeStyle, TimeZone timeZone) {
            DateTimeConverter converter = new DateTimeConverter();
            converter.setType(type);
            converter.setDateStyle(dateStyle);
            converter.setTimeStyle(timeStyle);
            converter.setTimeZone(timeZone);
            return converter.getAsString(FacesContext.getCurrentInstance(), new UIOutput(), date);
        }
    
    }
    

    Define it as a facelet-taglib in /META-INF/functions.taglib.xml (filename is free to 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 a XSD instead of a DTD; for an example see this answer)

    Register it as 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 already have the facelets.LIBRARIES definied, then you can just add the new path commaseparated; for Facelets 2.x, you need javax.faces.FACELETS_LIBRARIES context param instead)

    Declare it in the Facelets XHTML file as 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 as intended:

    <h:outputText 
        value="foo"
        title="#{uf:convertDateTime(bean.date, 'both', 'medium', 'short', bean.timeZone)}" />
    

    You can if necessary hardcode the type and styles in the function and give the method a different name which indicates those defaults.

    If you happen to use JSF utility library OmniFaces, then you can also use its #{of:formatDate()} function instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have the JSF update a component that's placed outside the
Is it possible to find out deployment path from JSF application? One more question
Is it possible to display the current date (today's) in JSF without using a
is there any component in jsf that provides pie charts with drill down facility
Is it possible with JSF to make ajax calls that will execute simultaneously (not
In JSF is it possible to have a datatable displays records as follows? [Name
Is it possible to test for enum equality in JSF? E.g. where stuff is
Is it possible to style JSF commandbutton tags to look like the following example:
I am wondering if it is possible to have a JSF handler and some
Is it possible to write own JSF 2.0 components with help of XSLT?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.