Announcement Announcement Module
Collapse
No announcement yet.
Surf support for JS file import Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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?

    Thanks,

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

    Code:
    <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.

    Cheers,

    Kev

    Comment


    • #3
      Incorrect usage?

      Kev,

      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.

      Regards,

      Bob





      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 eStore$WebApplicationStoreScriptContent@47105002': 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 eStore$WebApplicationStoreScriptContent@47105002': syntax error (/WEB-INF/webscripts/echo/echo.get.js#6)
      at org.springframework.extensions.webscripts.processo r.JSScriptProcessor.executeScript(JSScriptProcesso r.java:182)
      at org.springframework.extensions.webscripts.Abstract WebScript.executeScript(AbstractWebScript.java:952 )
      at org.springframework.extensions.webscripts.Declarat iveWebScript.execute(DeclarativeWebScript.java:86)
      at org.springframework.extensions.webscripts.Presenta tionContainer.executeScript(PresentationContainer. java:69)
      at org.springframework.extensions.webscripts.LocalWeb ScriptRuntimeContainer.executeScript(LocalWebScrip tRuntimeContainer.java:182)
      at org.springframework.extensions.webscripts.Abstract Runtime.executeScript(AbstractRuntime.java:307)
      at org.springframework.extensions.webscripts.Abstract Runtime.executeScript(AbstractRuntime.java:178)
      at org.springframework.extensions.webscripts.WebScrip tProcessor.executeBody(WebScriptProcessor.java:275 )
      at org.springframework.extensions.surf.render.Abstrac tProcessor.execute(AbstractProcessor.java:79)
      at org.springframework.extensions.surf.render.RenderS ervice.processComponent(RenderService.java:468)
      at org.springframework.extensions.surf.render.RenderS ervice.renderRawComponent(RenderService.java:970)
      at org.springframework.extensions.surf.render.RenderS ervice.renderRawComponent(RenderService.java:957)
      at org.springframework.extensions.surf.taglib.Compone ntIncludeTag.doStartTag(ComponentIncludeTag.java:3 9)
      at org.springframework.extensions.surf.render.TagServ ice.execute(TagService.java:214)
      at org.springframework.extensions.surf.render.TagServ ice.execute(TagService.java:148)
      at org.springframework.extensions.webscripts.Freemark erTagSupportDirective.executeTag(FreemarkerTagSupp ortDirective.java:92)
      at org.springframework.extensions.webscripts.GenericF reemarkerTagDirective.execute(GenericFreemarkerTag Directive.java:121)
      at freemarker.core.Environment.visit(Environment.java :261)
      at freemarker.core.UnifiedCall.accept(UnifiedCall.jav a:126)
      at freemarker.core.Environment.visit(Environment.java :208)
      at freemarker.core.Environment.process(Environment.ja va:188)
      at freemarker.template.Template.process(Template.java :237)
      at org.springframework.extensions.webscripts.processo r.FTLTemplateProcessor.process(FTLTemplateProcesso r.java:156)
      at org.springframework.extensions.webscripts.WebTempl ateProcessor.executeBody(WebTemplateProcessor.java :312)
      at org.springframework.extensions.surf.render.Abstrac tProcessor.execute(AbstractProcessor.java:79)
      at org.springframework.extensions.surf.render.RenderS ervice.processRenderable(RenderService.java:390)

      ...............

      Caused by: org.mozilla.javascript.EvaluatorException: syntax error (/WEB-INF/webscripts/echo/echo.get.js#6)
      at org.mozilla.javascript.DefaultErrorReporter.runtim eError(DefaultErrorReporter.java:109)
      at org.mozilla.javascript.DefaultErrorReporter.error( DefaultErrorReporter.java:96)
      at org.mozilla.javascript.Parser.addError(Parser.java :140)
      at org.mozilla.javascript.Parser.reportError(Parser.j ava:154)
      at org.mozilla.javascript.Parser.mustMatchToken(Parse r.java:240)
      at org.mozilla.javascript.Parser.xmlInitializer(Parse r.java:1634)
      at org.mozilla.javascript.Parser.unaryExpr(Parser.jav a:1584)
      at org.mozilla.javascript.Parser.mulExpr(Parser.java: 1519)
      at org.mozilla.javascript.Parser.addExpr(Parser.java: 1500)
      at org.mozilla.javascript.Parser.shiftExpr(Parser.jav a:1480)
      at org.mozilla.javascript.Parser.relExpr(Parser.java: 1454)
      at org.mozilla.javascript.Parser.eqExpr(Parser.java:1 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(Parser.java: 1365)
      at org.mozilla.javascript.Parser.orExpr(Parser.java:1 353)
      at org.mozilla.javascript.Parser.condExpr(Parser.java :1336)
      at org.mozilla.javascript.Parser.assignExpr(Parser.ja va:1321)
      at org.mozilla.javascript.Parser.expr(Parser.java:130 8)
      at org.mozilla.javascript.Parser.statementHelper(Pars er.java:1205)
      at org.mozilla.javascript.Parser.statement(Parser.jav a:655)
      at org.mozilla.javascript.Parser.parse(Parser.java:37 7)
      at org.mozilla.javascript.Parser.parse(Parser.java:31 5)
      at org.mozilla.javascript.Context.compileImpl(Context .java:2320)
      at org.mozilla.javascript.Context.compileString(Conte xt.java:1348)
      at org.mozilla.javascript.Context.compileString(Conte xt.java:1337)
      at org.springframework.extensions.webscripts.processo r.JSScriptProcessor.executeScript(JSScriptProcesso r.java:159)
      ... 109 more

      Comment


      • #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.

        Cheers,

        Kev

        Comment


        • #5
          Kev,

          GREAT! Got it working. Your comment. "...it 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:

          Code:
          // From Alfresco webscript (ala Spring). See also http://forum.springsource.org/showthread.php?t=95657 :
          <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.

          Thanks!,

          Bob

          Comment


          • #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):

            http://wiki.alfresco.com/wiki/3.3_Ja...orting_Scripts

            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

            Kev

            Comment

            Working...
            X