Tapestry
  1. Tapestry
  2. TAPESTRY-2390

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major 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:
      None
    • Environment:
      os x 10.4, firefox 2.0.0.13

      Description

      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.java.patch
        3 kB
        Chris Lewis
      2. ajax-external-js.js.patch
        6 kB
        Chris Lewis

        Activity

        Chris Lewis created issue -
        Chris Lewis made changes -
        Field Original Value New Value
        Attachment ajax-external-js.java.patch [ 12380970 ]
        Attachment ajax-external-js.js.patch [ 12380971 ]
        Chris Lewis made changes -
        Attachment ajax-external-js.js.patch [ 12380971 ]
        Chris Lewis made changes -
        Attachment ajax-external-js.js.patch [ 12380991 ]
        Chris Lewis made changes -
        Attachment ajax-external-js.java.patch [ 12380970 ]
        Chris Lewis made changes -
        Attachment ajax-external-js.js.patch [ 12380991 ]
        Chris Lewis made changes -
        Attachment ajax-external-js.js.patch [ 12381006 ]
        Attachment ajax-external-js.java.patch [ 12381005 ]
        Howard M. Lewis Ship made changes -
        Fix Version/s 5.0.13 [ 12313205 ]
        Fix Version/s 5.0.12 [ 12313048 ]
        Howard M. Lewis Ship made changes -
        Fix Version/s 5.0.13 [ 12313205 ]
        Fix Version/s 5.0 [ 12312018 ]
        Howard M. Lewis Ship made changes -
        Assignee Howard M. Lewis Ship [ hlship ]
        Howard M. Lewis Ship made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Howard M. Lewis Ship made changes -
        Fix Version/s 5.0.14 [ 12313214 ]
        Fix Version/s 5.0 [ 12312018 ]
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Mark Thomas made changes -
        Workflow jira [ 12429867 ] Default workflow, editable Closed status [ 12567777 ]
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12567777 ] jira [ 12590905 ]

          People

          • Assignee:
            Howard M. Lewis Ship
            Reporter:
            Chris Lewis
          • Votes:
            5 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development