hungsama / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

struts2_jquery.require many scripts fail with callBack function. #1006

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have previous version:
<artifactId>struts2-jquery-plugin</artifactId>
<version>3.5.1</version>

but I suppose that in 3.6.0 version this bug in struts2_jquery.require function 
will exist too.

JavaScript:

$(document).ready(function () {
        $.struts2_jquery.require(["portal/portal.js", "portal/atmosphere.js", "javascript/profile/rtc_adapter.js", "javascript/profile/chat_portal.js"], function () { 
portal.find().send('connect', {
                id: <s:property value="userId"/>,
                browser: navigator.userAgent
            }, function() {
                console.log("connected");
            });
  }, "/");
    });

The problem is in parameter 2 on require function (CallBack - its called after 
first loaded javacript). I expect this callBack function to be called after 
loading all javascripts.

This is the output of the FireBug:

struts2_jquery] load require script /portal/portal.js?s2j=3.5.1
GET http://localhost:8888/portal/portal.js?s2j=3.5.1

TypeError: portal.find(...) is null

This error appear because only the first script is loaded after call the 
CallBack function and chat_portal.js where is defined "portal" is not loaded 
yet.

Original issue reported on code.google.com by syt...@gmail.com on 11 Jul 2013 at 8:50

GoogleCodeExporter commented 9 years ago
The callBack function is called 4 times (the number of scripts in array times)

Original comment by syt...@gmail.com on 12 Jul 2013 at 11:18

GoogleCodeExporter commented 9 years ago
The solution that I have for this problem is:

$(document).ready(function () {

        $.struts2_jquery.require("portal/portal.js", function () {
            $.struts2_jquery.require("portal/atmosphere.js", function () {
                $.struts2_jquery.require("javascript/profile/rtc_adapter.js", function () {
                    $.struts2_jquery.require("javascript/profile/chat_portal.js", function () {
                        $.struts2_jquery.require("javascript/profile/jquery.balloon.js", function () {
                            portal.find().send('connect', {
                                id: <s:property value="userFromId"/>,
                                browser: navigator.userAgent
                            }, function () {
                                console.log("connected");
                            });
                        }, "/");
                    }, "/");
                }, "/");
            }, "/");
        }, "/");
    });

Original comment by syt...@gmail.com on 12 Jul 2013 at 11:22

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 12 Jul 2013 at 9:22