留言板

JQuery Conflict with Liferay 7 theme

thumbnail
William Gosse,修改在6 年前。

JQuery Conflict with Liferay 7 theme

Liferay Master 帖子: 533 加入日期: 10-7-4 最近的帖子
I think I'm having a JQuery conflict between the JQuery in Liferay 7 themes and JQuery being used by my portlets. I'm assuming the JQuery in the theme is being provided by the bootstrap 3. Our portlets are legacy Spring MVC portlets being migrated from our existing 6.2 installation.

I was wondering if anyone as a best practice for handling this kind of conflict.
thumbnail
William Gosse,修改在6 年前。

RE: JQuery Conflict with Liferay 7 theme (答复)

Liferay Master 帖子: 533 加入日期: 10-7-4 最近的帖子
We tried this fix which seems to have cured our problem:
http://www.learnandpost.com/2016/10/jquery-ui-with-liferay-7.html

Would still like to here any other suggestions as well.
Gunnar Brinkmann,修改在6 年前。

RE: JQuery Conflict with Liferay 7 theme

Junior Member 帖子: 53 加入日期: 11-12-2 最近的帖子
William Gosse:
We tried this fix which seems to have cured our problem:
http://www.learnandpost.com/2016/10/jquery-ui-with-liferay-7.html

Would still like to here any other suggestions as well.


I'd say that it's always dangerous / undefined to use different versions of a js framework in one html document.

One of multiple includes always wins regarding identical method signatures.

We're using primefaces in our portlets (same version in all portlets) and didn't have problems so far (crossing fingers).

An option could be a definition like "my portlet doesn't contain jQuery because the portlet container already imports jQuery". In this case the portlet should use a version of jQuery UI that is compatible with the jQuery version imported by the theme. As far as I know jQuery must be explicitely included when using jQuery UI, so it could be enough just to remove your jQuery include from the portlet view.

Another option could be (not sure, not tested) to provide "your" jQuery as an osgi module with some custom osgi module name. But when method calls are not namespaced (cannot be prefixed or are not automatically prefixed with this osgi name), this would be no option, the problem would stay the same (one of multiple includes wins).