Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-2390

Components or mixins requiring external javascript files and rendered via AJAX do not work


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0, 5.0.11, 5.0.12
    • Fix Version/s: 5.0.14
    • Component/s: JavaScript, tapestry-core
    • Labels:
    • Environment:
      os x 10.4, firefox


      To witness the breakage, create a simple page template that includes a form within a block. In this form include any component (or mixin) that requires an external JS file (like datefield, palette, etc). Create a zone and tie an actionlink to it. In the page class inject the block, and in the actionlink handler, return the injected block. The net result is that clicking on the link will fetch the form from the server via AJAX and put it in the zone.

      Now try to use the control, and you'll see it doesn't work. The problem is that there is currently no infrastructure for handling external scripts added via PageRenderSupport in an AJAX context. After a good bit of digging I realized that the PageRenderSupport implementation (actually the DocumentLinker impl) used for AJAX simply NOOPS several important methods, and specifically addScriptLink().

      I see 2 ways to fix this.

      1) Preemptively include all scripts from all components in the page, even if they are not initially rendered (which is the case of a block). This may be the best way to go IF that at the point of the initial page rendering T5 can know every component that may ever be rendered on that page.

      2) Extend the DocumentLinker implementation and tapestry.js to coordinate on an additional key in the AJAX response. This key would hold an array of all needed external JS files, and tapestry.js would handle loading them. The good thing about this approach is that the JS is only ever loaded if needed.

      I'll attach patches that implement method 2, patching TapestryModule.java and tapestry.js. The js extension eval()s the script code after the external files have loaded. It does this using the onload handler of the dynamically created script element. Granted this is a tad hackish and would need a bit more testing and thought (like preventing external JS from being loaded more than once), but it's a start.


        1. ajax-external-js.js.patch
          6 kB
          Chris Lewis
        2. ajax-external-js.java.patch
          3 kB
          Chris Lewis



            • Assignee:
              hlship Howard Lewis Ship
              chrislewis Chris Lewis


              • Created:

                Issue deployment