Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JQuery with SmartGWT

    Hello,

    I'm facing problem including jQuery library (needed for some external widget) into my SmartGWT app. The problem is that the application after including jquery by

    Code:
    <script src="js/wb/libs/jquery-1.7.1.min.js" type="application/javascript"></script>
    does not load properly (blank page is seen). I compared output of developer console for cases when included and when not and the difference is:

    Code:
    WARN:Canvas:registerStringMethods() called with a bad argument: function () {
     var newObj = (this instanceof Array) ? [] : {};
     for (i in this) {
     if (i == 'clone') continue;
     if (this[i] && typeof this[i] == "object") {
     newObj[i] = this[i].clone();
     } else newObj[i] = this[i]
     } return newObj;
    }
    I searched jquery JS file if there is function named registerStringMethods, but there is no such method. Any ideas what to do?:-)

    #2
    This is presumably some kind of collision between how JQuery augments native JavaScript objects such as Array and how SmartClient does it.

    Load JQuery before the SmartClient runtime - you can do this by using the "NoScript" versions of the GWT inherits and adding <script> tags to load the SmartClient runtime manually. This may correct the problem as we have a number of places where we compensate for JQuery.

    If it doesn't - that must be a JQuery function (as in, the function you've shown that includes 'if (i == 'clone') .. ') - can you find out what it's name is by searching the JQuery source?

    Comment


      #3
      Thanks for the quick answer. I'm not sure what do you really mean by NoScript versions of the GWT. Can you please provide some example or link to it how to do it?

      Btw my app includes GWT application this way:

      Code:
      <script type="text/javascript"> var isomorphicDir = "xyz.Main/sc/"; </script>
      <script type="text/javascript" src="xyz.Main/xyz.Main.nocache.js"></script>
      Thank you

      Comment


        #4
        If means that if you are inheriting eg com.smartgwt.SmartGwt instead inherit com.smartgwt.SmartGwtNoScript. You will then need to add <script src=> tags to load the JavaScript runtime files manually - this is ISC_Core.js et al and you can see the correct relative paths in Firebug among other tools.

        Comment


          #5
          OK thanks, anyway still same problem. My code now looks like:

          Main.gwt.xml
          Code:
          <inherits name="com.smartgwt.SmartGwtNoScript"/>
          main.html
          Code:
          <script src=cz.ctu.fee.voxport.Main/sc/modules/ISC_Core.js></script>
          <script src=xyz/sc/modules/ISC_Foundation.js></script>
          <script src=xyz/sc/modules/ISC_Containers.js></script>
          <script src=xyz/sc/modules/ISC_Grids.js></script>
          <script src=xyz/sc/modules/ISC_Forms.js></script>
          <script src=xyz/sc/modules/ISC_RichTextEditor.js></script>
          <script src=xyz/sc/modules/ISC_Calendar.js></script>
          <script src=xyz/sc/modules/ISC_DataBinding.js></script>
          I tried to check the jquery JS for the identical name of fuction (registerStringMethods) or some similar stuff (clone condition and so on) but didn't find anything.

          maybe I'm searching wrong? Anyway JQuery file I'm including can be found on
          http://code.jquery.com/jquery-1.7.1.js

          or here in minified version
          http://code.jquery.com/jquery-1.7.1.min.js

          Comment


            #6
            So the method you posted before:

            Code:
            function () {
             var newObj = (this instanceof Array) ? [] : {};
             for (i in this) {
             if (i == 'clone') continue;
             if (this[i] && typeof this[i] == "object") {
             newObj[i] = this[i].clone();
             } else newObj[i] = this[i]
             } return newObj;
            }
            .. is not part of JQuery, and not part of SmartGWT. It must be part of your app. What may be happening is that you are adding functions to the Array object in your application code?

            Comment


              #7
              Yep, it is not part of JQuery nor SmartGWT JS files (i posted). I came to the same conclusion. I was trying to find out from which file this code comes from. I debugged it via Chromium included tool (similar to firebug) and finally managed to find that this is part of 3rd party library (of my app) so you were right. Including this (3rd party) file does not makes any problem, but it seems that when included with JQuery, this function gets called.

              Anyway registerStringMethods is function from ISC JS files. Do you have any idea what from the noted function might cause the problems? Actually this function tries to extend the object with prototype clone function.

              I found an article from which code of 3rd party library comes from
              http://my.opera.com/GreyWyvern/blog/show.dml/1725165

              Comment


                #8
                You need to get rid of that code. Extending Object.prototype is terrible practice, not necessary, and there is no feasible way to work around it - what it does is add an extra property to every JavaScript object. This is as if, in Java, every HashMap you created had a bonus key - obviously not something you would consider it reasonable to work around.

                Comment


                  #9
                  Yes, I removed this code and it seems that it works OK now everything. I gotta test it more precisely but from the first view it is allright. Thanks a lot for your time and patience:-)

                  Comment

                  Working...
                  X