Liferay ist zum sechsten Mal in Folge ein Leader im Gartner Magic Quadrant. Hier mehr erfahren

Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
Riggy D
JavaScript content of portlet disappears after reload/refresh
4. April 2013 01:19
Antwort

Riggy D

Rang: New Member

Nachrichten: 2

Eintrittsdatum: 2. April 2013

Neue 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:

 1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 2
 3<portlet:defineObjects />
 4
 5Test text!
 6
 7<script>
 8init('http://localhost:8888/semantics.rdf#Attribute');
 9</script>
10<table>
11    <tbody>
12        <tr>
13            <td id="first-panel" style="vertical-align: top; width: 20em"></td>
14            <td id="second-panel" style="vertical-align: top"></td>
15        </tr>
16    </tbody>
17</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