3 Replies Latest reply on Apr 10, 2007 8:48 AM by Anette Engel

    JBoss 4.05GA + JPortal 2.4 & javascript problem

    Gaetano Sferra Newbie

      I wish to include a javascript file into a JSP portlet so I added the following on top of my JSP page:

      <%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
      <script type="text/javascript" src="/js/mylib.js"></script>

      When my portlet loads I got an "undefined object" javascript error while trying to invoke an object belonging to the included file (the same occurs if I try to use everything else - objects or functions - defined in that file).
      Every other script directly written in my JSP works well, such as:

      <script type="text/javascript">
      alert("Hey, this works");

      Thinking about a path problem I also tryed that:

      <%@taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
      <script type="text/javascript" src='<%= response.encodeURL(request.getContextPath() + "/js/mylib.js") %>'></script>

      achieving the same, identical and frustrating results.
      Please, help me, I really need to solve this matter.

      Thank you,
      Gaetano Sferra

        • 1. Re: JBoss 4.05GA + JPortal 2.4 & javascript problem
          Jon Whitmore Newbie

          Probably not the solution you were looking for, but this is what I did to get around not being able to figure out the path to my script:

          renderResponse.setProperty("HEADER_CONTENT", "<script type=\"text/javascript\">"+ script +"</script>");

          Above my script has been loaded off the file system by my portlet and I inject the script into the head "manually". Probably not an issue for a short script, but I would imagine that finding the correct path and setting that in your JSP is better in the long run when your server is under heavy use.

          • 2. Re: JBoss 4.05GA + JPortal 2.4 & javascript problem
            Gaetano Sferra Newbie

            Thank you nollie,
            your solution may be a good choice for short scripts (you could put it directly into the JSP without have to set the header content in the portlet methods) but I'm in dealing with a long script library and I wish to include it (yes, I know, it's the same because the browser must download the script file) gaining a better "human readable" html output. If someone else knows a better solution, please post it, otherwise I've no choice to put all the javascript code inside the JSP.

            • 3. Re: JBoss 4.05GA + JPortal 2.4 & javascript problem
              Anette Engel Newbie

              Replace the location /js/mylib.js with <%= renderRequest.getContextPath() %>/js/mylib.js i.e.

              <script type="text/javascript" src="<%= renderRequest.getContextPath() %>/js/mylib.js"></script>

              Best Regards,