2 Replies Latest reply on Mar 4, 2006 1:06 AM by Aron Gombas

    How-To add javascript libraries to a portlet view.

    Kevin J Citron Newbie

      I'm trying to use the dojo AJAX toolkit within a portlet view.jsp to no avail.
      Can anyone point out what the correct method is. Here is my view.jsp.
      None of the dojo widgets are rendered. Just plain HTML.
      dojo.js is in the same directory as view.jsp

      Thanks in advance.

      <%@ page contentType="text/html" language="java" %>
      <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
      <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
      <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
      <%@ page session="false" %>

      <script type="text/javascript">
       var djConfig = {
       isDebug: true
      <script type="text/javascript" src="dojo.js"></script>
      <script language="JavaScript" type="text/javascript">
       dojo.require("dojo.event.*"); // sophisticated AOP event handling
       dojo.require("dojo.io.*"); // for Ajax requests
       dojo.require("dojo.storage.*"); // a persistent local data cache
       dojo.require("dojo.json"); // serialization to JSON
       dojo.require("dojo.dnd.*"); // drag-and-drop
       dojo.require("dojo.fx.*"); // animations and eye candy
       dojo.require("dojo.widget.Editor"); // stable, portable HTML WYSIWYG

        • 1. Re: How-To add javascript libraries to a portlet view.
          Woodler Expert

          the easiest way (I believe) is to use the declarative injection of header content. In this case you can declare the js file to be included as link in the head tag, by adding this to your jboss-portlet.xml descriptor :

           <link type="text/javascript" href="/portlet-resources/dojo.js" />

          The only limitation is that you need to use the 'generic' layout , or any other layout that features the <p:headerContent /> jsp tag

          • 2. Re: How-To add javascript libraries to a portlet view.
            Aron Gombas Novice


            "mholzner" wrote:
            the easiest way (I believe) is to use the declarative injection of header content.

            I'd not suggest this, as it wouldn't be portable.

            I think the problem with your original approach is that URL's are probably wrong.
            This one is working for me perfectly in Kosmos:
            <script src="<c:url value="/pages/scripts/scriptaculous/prototype.js"/>" language="javascript"></script>

            An easy test that you can do is to use a JSP @include to include the JS. If you can see its content in the browser when checking the page source, then the URL is fine.