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

          Ted Goddard created issue -
          Ted Goddard made changes -
          Field Original Value New Value
          Link This issue depends on ICE-5211 [ ICE-5211 ]
          Hide
          Ted Goddard added a comment -

          Assigning to Ken for assignment.

          Show
          Ted Goddard added a comment - Assigning to Ken for assignment.
          Ted Goddard made changes -
          Assignee Ken Fyten [ ken.fyten ]
          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.
          Ted Goddard made changes -
          Assignee Ken Fyten [ ken.fyten ] Greg Dick [ greg.dick ]
          Ken Fyten made changes -
          Salesforce Case []
          Fix Version/s 2.0-Beta2 [ 10242 ]
          Assignee Priority P2
          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.
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22521 Tue Oct 05 16:36:20 MDT 2010 greg.dick ICE-6047 Initial check in
          Files Changed
          Commit graph ADD /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/render/ExternalScript.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22522 Tue Oct 05 16:37:28 MDT 2010 greg.dick ICE-6047 Added support for optional scripts to head region
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/event/BridgeSetup.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22523 Tue Oct 05 16:38:48 MDT 2010 greg.dick ICE-6047 Added support for optional scripts to head region
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/renderkit/DOMRenderKit.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22524 Tue Oct 05 16:39:21 MDT 2010 greg.dick ICE-6047 Added Annotation for external script reference for testing
          Files Changed
          Commit graph MODIFY /icefaces/scratchpads/sparkle/component/src/org/icefaces/component/commandlink/CommandLinkRenderer.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22525 Tue Oct 05 22:38:18 MDT 2010 greg.dick ICE-6047 repaired logic that was checking existence of contextParam
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/event/BridgeSetup.java
          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.)
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22575 Fri Oct 08 08:45:38 MDT 2010 greg.dick ICE-6047 Set the renderer transient
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/event/BridgeSetup.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22576 Fri Oct 08 08:55:00 MDT 2010 greg.dick ICE-6047 gMap key test is just for presence, it isn't a boolean flag enabling the functionality.
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/event/BridgeSetup.java
          Repository Revision Date User Message
          ICEsoft Public SVN Repository #22633 Thu Oct 14 15:18:29 MDT 2010 ted.goddard set ID on ExternalScript renderer to avoid head id (ICE-6047)
          Files Changed
          Commit graph MODIFY /icefaces2/trunk/icefaces/compat/components/src/main/java/com/icesoft/faces/component/gmap/GMapRenderer.java
          Commit graph MODIFY /icefaces2/trunk/icefaces/core/src/main/java/org/icefaces/impl/event/BridgeSetup.java
          Commit graph MODIFY /icefaces2/trunk/icefaces/compat/samples/component-showcase/web/WEB-INF/includes/templates/page-template.xhtml
          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.
          Ted Goddard made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Ken Fyten made changes -
          Fix Version/s 2.0.0 [ 10230 ]
          Ken Fyten made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Assignee Priority P2

            People

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

              Dates

              • Created:
                Updated:
                Resolved: