Foren

JavaScript content of portlet disappears after reload/refresh

Riggy D, geändert vor 11 Jahren.

JavaScript content of portlet disappears after reload/refresh

New Member Beiträge: 2 Beitrittsdatum: 02.04.13 Neueste Beiträge
Hi everyone,

I have a somewhat strange problem that I can't figure out why is happening, and googling has led me nowhere near a solution either.

To summarize the problem before I go into lengthy detail: The JavaScript content of my portlet only appears the first time I add the portlet to the portal! In other words, if I reload the page or go to the portal page at a later time, the JavaScript content is simply not displayed.

I have a portlet which is basically just a container for my JavaScript-GUI which I host on another server (localhost:8888). (And the JavaScript then again interacts with a Java application which is hosted on localhost:8080, where it gets the data to display).

The portlet is generated by Liferay SDK and the only modifications to the generated portlet are to the view.jsp.
I am using Liferay 6.1.1, bundled with Tomcat 7.0.27 (running on port 8081), and the bundled in-memory database.

view.jsp contains the following code:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineobjects />

Test text!

<script>
init('http://localhost:8888/semantics.rdf#Attribute');
</script>
<table>
	<tbody>
		<tr>
			<td id="first-panel" style="vertical-align: top; width: 20em"></td>
			<td id="second-panel" style="vertical-align: top"></td>
		</tr>
	</tbody>
</table>


In liferay-portlet.xml, I use <header-portlet-javascript> to refer to the javascript file that has the init function that is called in view.jsp (which needs to get an attribute of an rdf file as a parameter), and also refers to a couple of css-files that I'm using with <portlet-header-css>.

As mentioned, everything works splendidly the first time I add the portlet to the portal page. When I reload the page or visit it in another browser or something like that, only the "Test text!" is visible, the rest is simply gone and underneath it, the next portlet appears.

I have found nothing suspicious in the logs (I am just using the built-in logging and have checked all of the logs in tomcat_home/logs), and out of some error messages it seems like the JavaScript functions are still called when the GUI isn't displayed.

Has anyone got any idea about what could be the cause of this? Since there is JavaScript and different servers/ports involved, I was thinking that it might be because of the Same-Origin Policy, but then again I think it shouldn't work at all when I add the portlet either?

I would be extremely grateful for any advice, hints or strategies that could bring me further emoticon

Best,
Riggy