开发者

Odd rich:calendar bug

开发者 https://www.devze.com 2023-02-14 00:15 出处:网络
I\'m using a rich calendar control with manual suggestions enabled, and a date string of \"dd MMM yyyy\". Something like:

I'm using a rich calendar control with manual suggestions enabled, and a date string of "dd MMM yyyy". Something like:

<rich:calendar id="calStartDateTime" label="Test Calendar" 
popup="true" datePattern="dd MMM yyyy" />

Our QA department found an odd little quirk. If you type a date with the month in all caps, like "15 MAR 2011", and then popup the calendar control, the calendar trips out. It displays "undefined" for the month and "NaN" for the year, and the days of the month are filled in from 1 to 42.

Odd rich:calendar bug

I haven't found this bug reported anywhere, but it's possible I'm not searching for it right. Can anyone suggest a fix or workaround? We're using RichFaces 3.3.1.GA, and it would be difficult for us to change that at 开发者_开发技巧this moment.


OK, I finally figured it out. There's a bug in the JavaScript included in calendar.js with RichFaces 3.3.1. The parseDate() function splits the input string into year, month, and day pieces using a regular expression it builds up from the date pattern and the list of short months, (Jan|Feb|Mar ...). However, it runs the RE in case-insensitive mode. So the month piece can come back as "MAR", for example. It then calls a getMonthByLabel() function to convert the month to a number, but the string compares that does are case sensitive, so we get a failure to parse the month that doesn't cause a general failure of the parseDate() function, and everything goes off the rails.

It looks like it got fixed by RichFaces 3.3.3.Final though.

3.3.1.GA:

Richfaces.Calendar.getMonthByLabel = function(monthLabel, monthNames) {
var i = 0;
while (i < monthNames.length)
    if (monthNames[i] == monthLabel)
        return i;
    else
        i++;
};

3.3.3.Final:

Richfaces.Calendar.getMonthByLabel = function (monthLabel, monthNames) {
var toLowerMonthLabel = monthLabel.toLowerCase();
var i = 0;
while (i < monthNames.length) {
    if (monthNames[i].toLowerCase() == toLowerMonthLabel) {
        return i;
    }

    i++;
}
};
0

精彩评论

暂无评论...
验证码 换一张
取 消