ICEfaces
  1. ICEfaces
  2. ICE-6047

Automatic loading of external scripts

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-Beta1
    • Fix Version/s: 2.0-Beta2, 2.0.0
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      ICEfaces 2.0, Google maps

      Description

      As described in ICE-5211, it can be difficult to integrate components that require external scripts, such as

      http://maps.google.com/maps/api/js?sensor=false

      Evidence indicates that these external scripts must be loaded on initial page GET, so the best solution is to have the script loading as part of the page template.

      This can be implemented as an externalScript resource component automatically added to the HEAD resources, similar to bridge.js. The externalScript component should automatically detect any other components in the application that require external scripts. This can be done through a context parameter or an <ice:config> parameter. Additionally, it may be desirable to specify a script link to be loaded directly in web.xml (not associated with any particular component.)

      It is possible that <ice:config> will not run at the right time to ensure that the JavaScript is loaded when required.
       

        Issue Links

          Activity

          Hide
          Ted Goddard added a comment -

          Assigning to Ken for assignment.

          Show
          Ted Goddard added a comment - Assigning to Ken for assignment.
          Hide
          Ted Goddard added a comment -

          DOMRenderKit.addRenderer has visibility to all Renderers added to the application (and it is actually the Renderer that has the script dependency, not the component). Therefore, an annotation on the Renderer obtained via Class.getAnnotation() could be used to detect any required script resource URLs.

          Show
          Ted Goddard added a comment - DOMRenderKit.addRenderer has visibility to all Renderers added to the application (and it is actually the Renderer that has the script dependency, not the component). Therefore, an annotation on the Renderer obtained via Class.getAnnotation() could be used to detect any required script resource URLs.
          Hide
          Mark Collette added a comment -

          Let's use the gmap component renderer as an example:
          @ExternalScript("http://maps.google.com/maps.js", "com.icesoft.faces.gmapKey")

          If we put an annotation on it, that describes the script to include, then it can also have a field that describes a context-param to check for first, with which the application will opt into this mechanism. So, when "com.icesoft.faces.gmapKey" is specified, then the com.icesoft.faces.gmapKey context-param must exist, otherwise "http://maps.google.com/maps.js" will not be included.

          For other components, they might not specify the second field in the annotation, and so there won't be a requirement for a context-param to be specified, and so the script will always be included.

          Show
          Mark Collette added a comment - Let's use the gmap component renderer as an example: @ExternalScript("http://maps.google.com/maps.js", "com.icesoft.faces.gmapKey") If we put an annotation on it, that describes the script to include, then it can also have a field that describes a context-param to check for first, with which the application will opt into this mechanism. So, when "com.icesoft.faces.gmapKey" is specified, then the com.icesoft.faces.gmapKey context-param must exist, otherwise "http://maps.google.com/maps.js" will not be included. For other components, they might not specify the second field in the annotation, and so there won't be a requirement for a context-param to be specified, and so the script will always be included.
          Hide
          Ted Goddard added a comment -

          Loading the gmap script may not actually be a problem in general – the warning for the key may only appear if the gmap component is initialized.

          Show
          Ted Goddard added a comment - Loading the gmap script may not actually be a problem in general – the warning for the key may only appear if the gmap component is initialized.
          Hide
          Greg Dick added a comment -

          I've checked in some changes for this jira.

          I think this implementation has a few shortcomings. The renderers are only added to the RenderKit once at application startup which is a pretty blunt instrument. As an example, I've set the annotation for the gmap script on the commandLinkRenderer in Sparkle and if the context param is either set or not defined the script will be inserted in every render of every view. Are we sure we can't define something at the page level that would add some greater precision to this?

          Show
          Greg Dick added a comment - I've checked in some changes for this jira. I think this implementation has a few shortcomings. The renderers are only added to the RenderKit once at application startup which is a pretty blunt instrument. As an example, I've set the annotation for the gmap script on the commandLinkRenderer in Sparkle and if the context param is either set or not defined the script will be inserted in every render of every view. Are we sure we can't define something at the page level that would add some greater precision to this?
          Hide
          Ted Goddard added a comment -

          Page level would be better, but from what we can tell, it is not sufficient since a component that requires an external script can be added dynamically.

          Perhaps we should also add page-level control so that a developer can make use of it if they are aware that a full page refresh is required. (For instance, google map key being present in View Scope could also be sufficient to cause the external script to be rendered.)

          Show
          Ted Goddard added a comment - Page level would be better, but from what we can tell, it is not sufficient since a component that requires an external script can be added dynamically. Perhaps we should also add page-level control so that a developer can make use of it if they are aware that a full page refresh is required. (For instance, google map key being present in View Scope could also be sufficient to cause the external script to be rendered.)
          Hide
          Ted Goddard added a comment - - edited

          Existing implementation was essentially complete but needed a bit of voodoo: for some reason, the lack of an ID on the addComponentResource() component was causing the <head> to be assigned a different ID each time, resulting in a full page update.

          Additionally, the script for GMapRenderer required v2 Google Map JavaScript and the init parameter key appended to the URL.

          Show
          Ted Goddard added a comment - - edited Existing implementation was essentially complete but needed a bit of voodoo: for some reason, the lack of an ID on the addComponentResource() component was causing the <head> to be assigned a different ID each time, resulting in a full page update. Additionally, the script for GMapRenderer required v2 Google Map JavaScript and the init parameter key appended to the URL.

            People

            • Assignee:
              Greg Dick
              Reporter:
              Ted Goddard
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: