3 Replies Latest reply on Sep 6, 2005 5:58 AM by Hannes Stillerich

    JavaScript & jsp: can't load external script

    Hannes Stillerich Newbie

      I want to use the js table from http://www.activewidgets.com/. The source is all in grid.js that is packed within the war file. My portlet-jsp contains following lines:

      <script language="JavaScript" src="grid.js"></script>
      [...]
      <script language="JavaScript">
      // create ActiveWidgets Grid javascript object
      var obj = new Active.Controls.Grid;
      // set number of rows/columns
      obj.setRowProperty("count", 5);
      obj.setColumnProperty("count", 4);
      // provide cells text
      obj.setDataProperty("text", function(i, j){return i + "." + j});
      // write grid html to the page
      document.write(obj);
      </script>

      But the litte test table is not shown. The JavaScript Console says:
      Error: syntax error
      Source File: http://localhost:8081/portal/grid.js
      Line: 8
      Source Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      Error: Active is not defined
      Source File: http://localhost:8081/portal/
      Line: 307

      The Code is working offline but it seems that the grid.js couldn't be loaded for some reason. What is the problem?

        • 1. Re: JavaScript & jsp: can't load external script
          Dion Dodgen Newbie

          Hi Hannes,

          Well looking at this I would check to see what the application context name of my portlet is. This should provide a bit of information of your path to your war file resources.

          Then make sure the

          <script src= "" />
          matches the path of your portlet war.

          Your current path says that the grid.js is in the root folder of the core-war and I don't think you have it here.

          I would pop the .js file under my /WEB-INF directory in another folder of your portlets war so
          /WEB-INF/javascript/grid.js then reference it in the jsp script tags
          <script src="WEB-INF/javascript/grid.js" />


          or something like this.

          I hope this helps.

          Dion



          • 2. Re: JavaScript & jsp: can't load external script
            Hannes Stillerich Newbie

            Thank you for your reply :)

            "diondodgen" wrote:
            Hi Hannes,

            Well looking at this I would check to see what the application context name of my portlet is. This should provide a bit of information of your path to your war file resources.

            hmm, what do you exactly mean? I can retrieve only the 'portlet context name' [doView]
            PortletContext context = getPortletContext();
             System.out.println(context.getPortletContextName());

            But the value is null.
            "diondodgen" wrote:

            Then make sure the
            <script src= "" />
            matches the path of your portlet war.

            Your current path says that the grid.js is in the root folder of the core-war and I don't think you have it here.

            yes it is located there. Otherwise it can't be found (no syntax error in the js-console).
            "diondodgen" wrote:

            I would pop the .js file under my /WEB-INF directory in another folder of your portlets war so
            /WEB-INF/javascript/grid.js then reference it in the jsp script tags
            <script src="WEB-INF/javascript/grid.js" />

            I've tried that, but I can only access the (and other) file(s) in the root folder of the war where the jsp is located. Should I define the *.js and *.css as a resource?

            But I think, the main problem still stays: the js-console delivers the syntax error:
            Error: syntax error
            Source File: http://localhost:8081/portal/grid.js
            Line: 8
            Source Code:
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            and this causes the other error 'Active is not defined'. Unfortunately the source of the js-file is totally illegible. I cant locate the error.
            Maybe someone want to try out the table (licenced under the GPL):
            http://www.activewidgets.com/download/activewidgets-grid-1.0-gpl.zip

            Regards,
            Hannes

            • 3. Re: JavaScript & jsp: can't load external script
              Hannes Stillerich Newbie

              It is a bug in the javascript from activewidgets. I am not allowed to have

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              in my html-page. I am trying to remove the line from the index.jsp.
              But why I can access only files from the root folder is still confusing...