留言板

RE: DWR various portlets, multiple engine.js included. Incomplete Response.

Michal Sima,修改在10 年前。

DWR various portlets, multiple engine.js included. Incomplete Response.

New Member 帖子: 24 加入日期: 13-2-27 最近的帖子
Good day,

I have two working portlets that use DWR 3.0RC . Both have the following code in liferay-portlet.xml:

<footer-portlet-javascript>/dwr/engine.js</footer-portlet-javascript>
<footer-portlet-javascript>/dwr/util.js</footer-portlet-javascript>
<footer-portlet-javascript>/dwr/interface/DWRgate.js</footer-portlet-javascript>

Therefore, the /dwr/engine.js is included twice, if both portlets are in the same page:

<script src="/ONE-portlet/dwr/engine.js" type="text/javascript"></script>
[...]
<script src="/TWO-portlet/dwr/engine.js" type="text/javascript"></script>

In that case I have the "Incomplete Response from the Server" alert on page load. This problem disappears when I am including engine.js only once (I remove <tooter-portlet-javascript> tag from one the portlets). However, I cannot do it, as I cannot be sure if the user has placed one or two porlets on the same page.

I have seen some tips that the problem is related to namespace, how can I differ namespaces for both javascript DWR engines, or check if engine.js is already included or not? I cannot modify engine.js, its genereted inside dwr.jar.

Cheers,
Michal Sima,修改在10 年前。

RE: DWR various portlets, multiple engine.js included. Incomplete Response.

New Member 帖子: 24 加入日期: 13-2-27 最近的帖子
If someone has the same problem:

It seems that requireJS (http://requirejs.org) can be the answer. It works for me now, I used to see mentioned error a couple of times, but loading JS with the following methods seems to do the trick:

Within .jsp

<script data-main="/NameOf-portlet/js/main.js" src="/path/to/js/require.js"></script>

Within main.js

if (typeof dwr == 'undefined') {

require(["/NameOf-portlet/dwr/engine.js"], function() {
require(["/NameOf-portlet/dwr/util.js"], function() {
require(["/NameOf-portlet/dwr/interface/BrowseDWRGate.js"], function() {
//alert("Engine js incldued");
});
});
});
}else {
require(["/NameOf-portlet/dwr/interface/DWRGate.js"], function() {
//alert("Just gate incldued");
});
}
}

As one can see, if dwr is already defined, only interface class will be loaded. Works good!

(note, it was not working when require.js was included as footer-portlet-javascript, data-main="" is necessary)