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 8104475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:51:19+00:00 2026-06-05T23:51:19+00:00

I am using JSF 2.0 and RichFaces 4. For the date input, I am

  • 0

I am using JSF 2.0 and RichFaces 4. For the date input, I am trying to force the pattern mm/dd/yyyy.

<h:inputText value="#{bean.startDate}">
    <f:convertDateTime pattern="mm/dd/yyyy"/>
</h:inputText>

When user actually enters a date with a 2-digit year like so mm/dd/yy, then the converter automatically converts the year to 4 digits. This is undesired. How can I stop it from doing that without creating a custom converter? Is this a bug in the JSF converter?

  • 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-05T23:51:22+00:00Added an answer on June 5, 2026 at 11:51 pm

    This isn’t a bug. That’s just how SimpleDateFormat works. Here’s a cite of relevance from the linked javadoc:

    • Year: If the formatter’s Calendar is the Gregorian calendar, the following rules are applied.
      • …
      • For parsing, if the number of pattern letters is more than 2, the year is interpreted literally, regardless of the number of digits. So using the pattern “MM/dd/yyyy”, “01/11/12” parses to Jan 11, 12 A.D.
      • …

    The JSF <f:convertDateTime> is just using it under the covers. Your best bet is to extend the DateTimeConverter and validate the length of the submitted value before passing through to the real DateTimeConverter. You can’t go around creating a custom converter, but it’s after all fairly simple.

    @FacesConverter("myDateTimeConverter")
    public class MyDateTimeConverter extends DateTimeConverter {
    
        public MyDateTimeConverter() {
            setPattern("MM/dd/yyyy");
        }
    
        @Override
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
            if (value != null && value.length() != getPattern().length()) {
                throw new ConverterException("Invalid format");
            }
            return super.getAsObject(context, component, value);
        }
    
    }
    

    Use it as follows:

    <h:inputText ... converterMessage="Please enter date in MM/dd/yyyy format">
        <f:converter converterId="myDateTimeConverter" />
    </h:inputText>
    

    Please note that I fixed the mm (minutes) in the pattern to be MM (months).

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

Sidebar

Related Questions

I am using JSF, richfaces 4 stuff and i want to call a bean
I am using JSF along with RichFaces and Spring Webflow. I am trying to
I am using JSF 1.2 and Richfaces 3.3.FINAL. I have an inputText which must
I am using JSF with richfaces. I am using convertDateTime of core ip to
I made a MVC based website using JSF 2.0 and RichFaces 4. Every input
I am using JSF2.0 with Richfaces 4.x i am trying to get input myfield
I'm using Richfaces JSF and I want to iterate over an Map<Object,Object> . I
I'm using JSF 1.2 with Richfaces and Facelets. I have an application with many
I'm using JSF (Mojarra 1.2) with Richfaces (3.3.2) within some facelets which are used
Using Richfaces 3.3.0GA, jsf 1.2_14 and facelets. I have a richfaces ModalPanel with an

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.