Announcement Announcement Module
No announcement yet.
Surf support for JS file import Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Surf support for JS file import

    I am familiar with Alfresco Web Scripts where I used the following syntax to include JavaScript (JS) library files:

    <import resource="classpath:alfresco/extension/templates/webscripts/com/ihg/hcm/utils.js">

    This is quite handy! Looks like syntax straight out of a Spring application context file.

    I attempted to use this syntax in a JS file within Spring Surf to no avail. I am hoping that some form of the import functionality was ported as part of moving Web Scripts to Spring Surf. Is this the case?

    Otherwise, it looks rather painful to accomplish a file import in ECMA. Am I missing something?


    Last edited by BoJo; Sep 22nd, 2010, 10:44 PM.

  • #2
    Yes this works fine in SpringSurf - we use it all the time in Alfresco Share (yes it is very, very handy!)

    They should be no tricks to using it, here is an example:

    <import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js">
    You need to ensure you have a leading "/" character in your classpath from the example you sent I think.




    • #3
      Incorrect usage?


      I must be doing something wrong. We I add the following line:

      <import resource="classpath:/js/directwebUtil.js">

      to my JavaScript file (under /webscripts), I get the (abbreviated) error below when the page is rendered. The full stack trace is attached (too large to post).

      I'm running 1.0.0.M3.



      ERROR: org.springframework.extensions.webscripts.Abstract Runtime - Exception from executeScript - redirecting to status template error: 08230000 Failed to load script 'org.springframework.extensions.webscripts.Resourc [email protected]': syntax error (/WEB-INF/webscripts/echo/echo.get.js#6)
      org.springframework.extensions.webscripts.WebScrip tException: 08230000 Failed to load script 'org.springframework.extensions.webscripts.Resourc [email protected]': syntax error (/WEB-INF/webscripts/echo/echo.get.js#6)
      at org.springframework.extensions.webscripts.processo r.JSScriptProcessor.executeScript(JSScriptProcesso
      at org.springframework.extensions.webscripts.Abstract WebScript.executeScript( )
      at org.springframework.extensions.webscripts.Declarat iveWebScript.execute(
      at org.springframework.extensions.webscripts.Presenta tionContainer.executeScript(PresentationContainer. java:69)
      at org.springframework.extensions.webscripts.LocalWeb ScriptRuntimeContainer.executeScript(LocalWebScrip
      at org.springframework.extensions.webscripts.Abstract Runtime.executeScript(
      at org.springframework.extensions.webscripts.Abstract Runtime.executeScript(
      at org.springframework.extensions.webscripts.WebScrip tProcessor.executeBody( )
      at tProcessor.execute(
      at ervice.processComponent(
      at ervice.renderRawComponent(
      at ervice.renderRawComponent(
      at ntIncludeTag.doStartTag( 9)
      at ice.execute(
      at ice.execute(
      at org.springframework.extensions.webscripts.Freemark erTagSupportDirective.executeTag(FreemarkerTagSupp
      at org.springframework.extensions.webscripts.GenericF reemarkerTagDirective.execute(GenericFreemarkerTag
      at freemarker.core.Environment.visit( :261)
      at freemarker.core.UnifiedCall.accept(UnifiedCall.jav a:126)
      at freemarker.core.Environment.visit( :208)
      at freemarker.core.Environment.process(Environment.ja va:188)
      at freemarker.template.Template.process( :237)
      at org.springframework.extensions.webscripts.processo r.FTLTemplateProcessor.process(FTLTemplateProcesso
      at org.springframework.extensions.webscripts.WebTempl ateProcessor.executeBody( :312)
      at tProcessor.execute(
      at ervice.processRenderable(


      Caused by: org.mozilla.javascript.EvaluatorException: syntax error (/WEB-INF/webscripts/echo/echo.get.js#6)
      at org.mozilla.javascript.DefaultErrorReporter.runtim eError(
      at org.mozilla.javascript.DefaultErrorReporter.error(
      at org.mozilla.javascript.Parser.addError( :140)
      at org.mozilla.javascript.Parser.reportError(Parser.j ava:154)
      at org.mozilla.javascript.Parser.mustMatchToken(Parse
      at org.mozilla.javascript.Parser.xmlInitializer(Parse
      at org.mozilla.javascript.Parser.unaryExpr(Parser.jav a:1584)
      at org.mozilla.javascript.Parser.mulExpr( 1519)
      at org.mozilla.javascript.Parser.addExpr( 1500)
      at org.mozilla.javascript.Parser.shiftExpr(Parser.jav a:1480)
      at org.mozilla.javascript.Parser.relExpr( 1454)
      at org.mozilla.javascript.Parser.eqExpr( 410)
      at org.mozilla.javascript.Parser.bitAndExpr(Parser.ja va:1399)
      at org.mozilla.javascript.Parser.bitXorExpr(Parser.ja va:1388)
      at org.mozilla.javascript.Parser.bitOrExpr(Parser.jav a:1377)
      at org.mozilla.javascript.Parser.andExpr( 1365)
      at org.mozilla.javascript.Parser.orExpr( 353)
      at org.mozilla.javascript.Parser.condExpr( :1336)
      at org.mozilla.javascript.Parser.assignExpr(Parser.ja va:1321)
      at org.mozilla.javascript.Parser.expr( 8)
      at org.mozilla.javascript.Parser.statementHelper(Pars
      at org.mozilla.javascript.Parser.statement(Parser.jav a:655)
      at org.mozilla.javascript.Parser.parse( 7)
      at org.mozilla.javascript.Parser.parse( 5)
      at org.mozilla.javascript.Context.compileImpl(Context .java:2320)
      at org.mozilla.javascript.Context.compileString(Conte
      at org.mozilla.javascript.Context.compileString(Conte
      at org.springframework.extensions.webscripts.processo r.JSScriptProcessor.executeScript(JSScriptProcesso
      ... 109 more


      • #4
        Can you post the first few lines of echo.get.js? As the syntax error suggest the import line isn't formed correctly - as if it is processed by WebScripts, then it is removed *before* the actual script is processed by Rhino.




        • #5

          GREAT! Got it working. Your comment. " is removed *before* the actual script is processed by Rhino" made me think about the fact that I had a comment on the first line of the echo.get.js code:

          // From Alfresco webscript (ala Spring). See also :
          <import resource="classpath:/js/directwebUtil.js">
          // Display various Object properties
          function show_props(obj, objName) {
             var result = "";
             for (var i in obj) {
                result += objName + "." + i + " = " + obj[i] + "<br />";
             return result;
          However, all my examples have the <import> statements FIRST. Once I removed the comment on the first line, it worked.

          It would be nice if the pre-processor allowed comments, but I can certainly live without it. Very useful.




          • #6
            Yes indeed that is why I wanted to you post it, so I could see if there was anything above. As you've correctly guessed, there are no comments etc. allowed because it's all done pre javascript processing - and the preprocessor doesn't understand javascript comments etc. (to make it simple and fast!) so there is that cavet. It follows the information found here (as that is where the code comes from originally):


            Anyway, glad it's working now.

            >This is quite handy! Looks like syntax straight out of a Spring application context file.
            and yes that was on purpose