Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Michal Sima
DWR various portlets, multiple engine.js included. Incomplete Response.
June 6, 2013 4:16 AM
Answer

Michal Sima

Rank: New Member

Posts: 23

Join Date: February 27, 2013

Recent Posts

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
RE: DWR various portlets, multiple engine.js included. Incomplete Response.
June 20, 2013 9:55 AM
Answer

Michal Sima

Rank: New Member

Posts: 23

Join Date: February 27, 2013

Recent Posts

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)