掲示板

not loading js file in module proect.

6年前 に Ravi Shankar によって更新されました。

not loading js file in module proect.

Junior Member 投稿: 40 参加年月日: 16/07/13 最新の投稿
Hi All

i am new in liferay 7 environment, ryt now i am facing problem regarding including js files in modules project, so according to David H
suggestion i followed this link :

https://github.com/liferay/liferay-portal/blob/master/modules/apps/foundation/contacts/contacts-
web/src/main/java/com/liferay/contacts/web/internal/portlet/ContactsCenterPortlet.java#L130-L131 , so i am able to
load one js file but i am not able to load more than one js file, my sample code is:

@Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=StudentDetails Portlet",
"com.liferay.portlet.header-portlet-css=/html/css/main.css",
"com.liferay.portlet.header-portlet-css=/html/css/sub_main.css",
"com.liferay.portlet.header-portlet-javascript=/html/Jquery_Grid/js/jquery-3.1.1-min.js",
"com.liferay.portlet.header-portlet-javascript=/html/Jquery_Grid/js/test.js",
"com.liferay.portlet.header-portlet-javascript=/html/Jquery_Grid/js/test2.js",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class

here test.js is loading but test2.js is unable to load so please suggest me how i could solve this problem




Thanks with Regards;
Ravi Shankar
thumbnail
6年前 に Mayur Patel によって更新されました。

RE: not loading js file in module proect.

Expert 投稿: 358 参加年月日: 10/11/17 最新の投稿
Hi Ravi,

You can import static resources in below way also,


First of all you need to add webcontext path in your modules bnd file.

Web-ContextPath: /my-custom-portlet

After adding web context path you can add static resource inside META-INF folder.

main\resources\META-INF\resources\css

You can access CSS files added in above folder by adding following line in your code.

<link href="/o/my-custom-portlet/css/my-custom.css" rel="stylesheet" type="text/css">

Similar way you can add and use other static resource like JS and Images.


Thanks !