开发者

Grails Calendar plugin throws stack / recursion error

开发者 https://www.devze.com 2023-04-07 05:49 出处:网络
Calendar plugin version :CURRENT RELEASE1.2.1 I followed steps as mentioned in the grails plugin documentation, I get the following error in all types of browser

Calendar plugin version :CURRENT RELEASE 1.2.1

I followed steps as mentioned in the grails plugin documentation, I get the following error in all types of browser

Chrome 14.0835: Uncaught RangeError: Maximum Callstack size exceeded.

Firefox 6.02: Too much recursion calendar.js line 1851

IE 9: Out of stack 开发者_JAVA技巧space calendar.js line 1850


The offending jscalendar code is this:

Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
Date.prototype.setFullYear = function(y) {
    var d = new Date(this);
    d.__msh_oldSetFullYear(y);
    if (d.getMonth() != this.getMonth())
        this.setDate(28);
    this.__msh_oldSetFullYear(y);
};

Which redefines Date.setFullYear(). Have a look at comments #124 and #125 on this "old jscalendar" page.

Comment #124 (by Chris Lively)

Suggests updating calendar.js (near the bottom, ~line 1850).

For those getting the recursion error. You just need to comment a few lines. See below.

//Date.prototype.msh_oldSetFullYear = Date.prototype.setFullYear;
Date.prototype.setFullYear = function(y) {
    var d = new Date(this);
    //d.msh_oldSetFullYear(y);
    if (d.getMonth() != this.getMonth())
        this.setDate(28);
    //this._msholdSetFullYear(y);
};

Comment #125 (reply by larisa)

The problem with recursion occurs due to multiple includes of calendar JavaScript on a page. As a result Date patch redefines setFullYear function twice and causes infinite loop when it gets executed. We fixed it by making sure that function is redefined only once:

if(Date.prototype.msh_oldSetFullYear == null) {
    Date.prototype.msh_oldSetFullYear = Date.prototype.setFullYear;
}

Both of these suggest updates to calendar.js, which isn't ideal since it's delivered with the plugin.

Two suggestions:

  • Make sure you're not importing the calendar resources twice. Do you have a <calendar:resources/> in your main layout and your view GSP? If so, remove one of them.
  • If that doesn't work, perhaps use a different plugin. The calendar plugin looks like it hasn't been updated in a while (it's using an older version of jscalendar). If you're feeling ambitious, you could go update the plugin yourself!


This works for me:

if (Date.prototype.__msh_oldSetFullYear == null) {
    Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
}
Date.prototype.setFullYear = function(y) {
    var d = new Date(this);
    Date.prototype.__msh_oldSetFullYear.apply(d, arguments);
    if (d.getMonth() != this.getMonth())
        this.setDate(28);
    Date.prototype.__msh_oldSetFullYear.apply(this, arguments);
};


The way I resolved this issue is

1) Downloaded the source of the plugin 2) Created a plugin with the same name locally. 3) Copied the original source files to the local plugin I created 4) Changed the javascript file as suggested above 5) Compile and package the plugin 6) Removed the old plugin in my main project 7) Installed the newly created plugin from the zip file created from step 5.

It worked like a charm.

Thanks Rob Hruska for pointing me where to comment in the javascript file


I was facing same issue, I had placed <calendar:resources/> in my main jsp as well as in the template which was rendered in the jsp. Removing one of them solved the issue.

0

精彩评论

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

关注公众号