掲示板

Using javascript in portlets

16年前 に Sarah Killcoyne によって更新されました。

Using javascript in portlets

New Member 投稿: 14 参加年月日: 08/04/10 最新の投稿
Hi, I searched around the forum for this and didn't find the answer hopeing someone here knows emoticon

In my war file (MyPortlet.war) I have located javascript in two places: MyPortlet/WEB-INF/js MyPortlet/WEB-INF/jsyui

I have included all scripts using <header-portlet-javascript>/WEB-INF/js/myscript.js</header-portlet-javascript> in the liferay-portlet.xml. If I view the source after the portlets have been loaded the paths look like:
<script src="/MyPortlet/WEB-INF/js/myscript.js" type="text/javascript></script>

However, if I attempt to use any functions from within a script included that way I get a "[function name] is not defined" from the firebug console. I got around this with the YUI scripts by including them directly in my jsp using the url's as the source (rather than pointing to my local copy of them). I clearly can't do the same thing with any of my local scripts.

I see the same sort of thing with my css file included the same way in that none of the styles are applied.

Any help with this would be greatly appreciated.
Sarah

ETA: It would also be really nice if I could add javascript using the <header-portlet-javascript> tags from urls (ie, the yui libs) without have the war context being tacked on to the front of it.
thumbnail
16年前 に Björn Ryding によって更新されました。

RE: Using javascript in portlets

Liferay Master 投稿: 582 参加年月日: 07/05/16 最新の投稿
To make sure that your code is called last, try wrapping the JavaScript calls with:

jQuery(document).last(function(){
// Your JavaScript calls go here.
});
16年前 に Sarah Killcoyne によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 14 参加年月日: 08/04/10 最新の投稿
I'm not sure I understand what that will do. The java script files are being put correctly into the <head> tags for the entire page and the methods don't get called until a user interacts with a for in the portlet. Again, I could make it work by externalzing the scripts but I can't do that for all of them.
thumbnail
16年前 に Jerry Niu によって更新されました。

RE: Using javascript in portlets

Expert 投稿: 451 参加年月日: 06/06/21 最新の投稿
Yupe, you can include your library's in the meta and reference them in the portlet.

In some cases, you might want to use the jquery wrapper.
16年前 に Sarah Killcoyne によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 14 参加年月日: 08/04/10 最新の投稿
Ok, and I've done that. But any time I try to access one of the functions within a javascript file that I've included I get a [method name] not defined error in the page. I was able to get around it by referencing external url's but that won't work for everything. All the scripts that I've written directly into the jsp page work without the jquery thing so...what is going wrong when I try to use one of the methods in a file I've included using the inclusion tags in the xml?
16年前 に Sarah Killcoyne によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 14 参加年月日: 08/04/10 最新の投稿
Ug...it's a tomcat thing. I pulled the js directories out of WEB-INF and it was able to read them.
thumbnail
16年前 に Björn Ryding によって更新されました。

RE: Using javascript in portlets

Liferay Master 投稿: 582 参加年月日: 07/05/16 最新の投稿
Have you checked with Firebug that the scripts are loaded correctly?
thumbnail
15年前 に steffen schuler によって更新されました。

RE: Using javascript in portlets

Regular Member 投稿: 137 参加年月日: 08/05/12 最新の投稿
Hi. this does work pretty well, because I'am storing the JavaScript Files locally:

<liferay-portlet-app>
<portlet>
<portlet-name>OpenLayer</portlet-name>
<instanceable>true</instanceable>
<header-portlet-css>/resources/OpenLayer_2.7/theme/default/style.css</header-portlet-css>
<header-portlet-css>/resources/style.css</header-portlet-css>
<header-portlet-javascript> /resources/OpenLayer_2.7/OpenLayers.js</header-portlet-javascript>
</portlet>
...

but if I want to use a remote URL like

...
<header-portlet-javascript>http://openlayers.org/api/OpenLayers.js</header-portlet-javascript>
...

it does not work. It seems like it is always looking for the portal context and building the path to the JavaScript resource itself. Within the generated html I see something like:

<script src="/OSMPortlet/http://openlayers.org/api/OpenLayers.js"/>



Does anybody now how to include/reference externally hosted JavaScript files declarative? I really would like to have most of the JavaScript stuff in the Header of my page instead of having it everywhere : )
15年前 に Matt King によって更新されました。

RE: [Liferay Forums][3. Development] RE: Using javascript in portlets

Junior Member 投稿: 60 参加年月日: 08/07/10 最新の投稿
It’s usually best practice to load javascript last on a page, to reduce visible page load times to user…



From: steffen schuler from liferay.com [mailto:no-reply@liferay.com]
Sent: Thursday, December 18, 2008 11:38 AM
To: mb.239390.1807190@events.liferay.com
Subject: [Liferay Forums][3. Development] RE: Using javascript in portlets <mb.239390.1807190@events.liferay.com>



Hi. this does work pretty well, because I'am storing the JavaScript Files locally:

<liferay-portlet-app>
<portlet>
<portlet-name>OpenLayer</portlet-name>
<instanceable>true</instanceable>
<header-portlet-css>/resources/OpenLayer_2.7/theme/default/style.css</header-portlet-css>
<header-portlet-css>/resources/style.css</header-portlet-css>
<header-portlet-javascript> /resources/OpenLayer_2.7/OpenLayers.js</header-portlet-javascript>
</portlet>
...

but if I want to use a remote URL like

...
<header-portlet-javascript>http://openlayers.org/api/OpenLayers.js</header-portlet-javascript>
...

it does not work. It seems like it is always looking for the portal context and building the path to the JavaScript resource itself. Within the generated html I see something like:

<script src="/OSMPortlet/http://openlayers.org/api/OpenLayers.js"/>



Does anybody now how to include/reference externally hosted JavaScript files declarative? I really would like to have most of the JavaScript stuff in the Header of my page instead of having it everywhere : )
--
Liferay Message Boards
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1807190
mb.239390.1807190@events.liferay.com
http://www.liferay.com
15年前 に ivan provalov によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 1 参加年月日: 09/02/10 最新の投稿
Steffen, did you find out the solution for this? I am having the same issue.

Thanks,

IP
14年前 に Damien Harter によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 2 参加年月日: 09/08/27 最新の投稿
I'm starting with Liferay too and I want to integrate OpenLayers' javascript files. Could you send to me your Portlet integrating OpenLayer ? Here is my email address: damsss at gmail dot com.
thx in advance.
14年前 に Damien Harter によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 2 参加年月日: 09/08/27 最新の投稿
ok, got it ! Contact me if someone is interested
14年前 に Matthew W Breiner によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 1 参加年月日: 09/11/24 最新の投稿
Damien,

I just found the need for the same ... my email is Matthew Breiner at Hotmail dot com.

Thanks!
thumbnail
14年前 に Danny Francisco によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 10 参加年月日: 08/12/12 最新の投稿
Hi Damien,

Been struggling in using openlayers in liferay too. my email is dcfran at hotmail dot com

Thanks,

Danny
thumbnail
14年前 に Danny Francisco によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 10 参加年月日: 08/12/12 最新の投稿
Got it to work. http://dannyfrancisco.homelinux.org
I will try other maps later.
14年前 に emre yıldırım によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 1 参加年月日: 10/01/31 最新の投稿
Me too I need to integrate openlayers and liferay, Can anyone help me for this ? pls...
12年前 に Ryan Burke によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 1 参加年月日: 11/08/18 最新の投稿
Has anyone got openlayers to work in a Vaadin portlet in Liferay? My portlet is correctly pulling down the remote openlayers js file, but I get errors due to BaseLayer and MaxExtent being null when I load the page.
12年前 に harini P S によって更新されました。

RE: Using javascript in portlets

New Member 投稿: 1 参加年月日: 11/11/10 最新の投稿
Hi sarah,

checked out with this forum and got to know u are using yui js api.I'm completely new to that technology and i wanted to learn that so can u please help in developing the YUI concepts in my project.

Thanks in advance.