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

  • Home
  • SEARCH
  • 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 8291987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:18:54+00:00 2026-06-08T13:18:54+00:00

I’m consuming a REST webservice and directly using the JAXB objects in my view.

  • 0

I’m consuming a REST webservice and directly using the JAXB objects in my view. One has a date as a XMLGregorianCalendar like this:

@XmlAttribute(name = "record")
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar record;

While trying to use a standard converter

<h:outputText value="#{bean.value.record}" >
  <f:convertDateTime pattern="dd.MM.yy" />    
</h:outputText>  

I get the error message (translated into english) in my JSF2 environment (JBoss-7.1.1-Final)

javax.faces.convert.ConverterException: fSelection:dtSelection:0:j_idt42:
Converting of '2012-07-25T20:15:00' into string not possible.

It seems, the type XMLGregorianCalendar is not supported by the default converter. I’m wondering if a JSF converter for this date type is available, because this requirement does not seem to be that unusual …

Edit Ravi provided a functional example of a custom converter, but this seems to be to unflexible:

  • the pattern is hardcoded
  • no support for the user local
  • 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-06-08T13:18:57+00:00Added an answer on June 8, 2026 at 1:18 pm

    The value should be of type java.util.Date.

    So get the Date object from the XMLGregorianCalendar like this:

    record.toGregorianCalendar().getTime();
    

    UPDATE:

    You can use like this:

    <h:outputText value="#{bean.value.record.toGregorianCalendar().time}" >
        <f:convertDateTime pattern="dd.MM.yy" />    
    </h:outputText>
    

    This should actually work but since you said you are getting an IllegalAccessException, I am not sure for the exact reason.

    Alternatively, you can also write your own converter if you would like to, the converter will look like this:

    And if you want to use the same attributes that you would use with a dateTimeConverter, then you need to pass them as attributes to the component and extend DateTimeConverter like this:

    @FacesConverter("com.examples.Date")
    public class XMLGregorianCalConverter extends DateTimeConverter {
     private static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getTimeZone("GMT");
     private String dateStyle = "default";
     private Locale locale = null;
     private String pattern = null;
     private String timeStyle = "default";
     private TimeZone timeZone = DEFAULT_TIME_ZONE;
     private String type = "date";
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String newValue) {
        // TODO Auto-generated method stub
        return null;
    }
    
    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Map<String, Object> attributes = component.getAttributes();
        if(attributes.containsKey("pattern")){
            pattern = (String) attributes.get("pattern");
        }
        setPattern(pattern);
        if(attributes.containsKey("locale")){
            locale = (Locale) attributes.get("locale");
        }
        setLocale(locale);
        if(attributes.containsKey("timeZone")){
            timeZone = (TimeZone) attributes.get("timeZone");
        }
        setTimeZone(timeZone);
        if(attributes.containsKey("dateStyle")){
            dateStyle = (String) attributes.get("dateStyle");
        }
        setDateStyle(dateStyle);
        if(attributes.containsKey("timeStyle")){
            timeStyle = (String) attributes.get("timeStyle");
        }
        setTimeStyle(timeStyle);
        if(attributes.containsKey("type")){
            type = (String) attributes.get("type");
        }
        setType(type);
    
        XMLGregorianCalendar xmlGregCal = (XMLGregorianCalendar) value;
        Date date = xmlGregCal.toGregorianCalendar().getTime();
        return super.getAsString(context, component, date);
    }
    
    }
    

    and use on your page like this:

    <h:outputText value="#{bean.value.record}" >
        <f:converter converterId="com.examples.Date" />
        <f:attribute name="pattern" value="dd.MM.yy" />
    </h:outputText>
    

    Code inspired/copied from this question: JSF convertDateTime with timezone in datatable

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.