ICEfaces
  1. ICEfaces
  2. ICE-2542

Portlet-friendly injection of 3rd party JavaScript

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7DR#3
    • Fix Version/s: 1.7Beta1, 1.7
    • Component/s: Framework, ICE-Components
    • Labels:
      None
    • Environment:
      portal portlet

      Description

      Some components require 3rd party JavaScript libraries to be available to function properly. Current examples would be the Rich Text Editor (based on FCKEdit) and GMap (Google Maps) components. At the moment, we inject these additional scripts using techniques that enhance the <head>. However, in a portlet environment, the code path that does this injection is not executed. With ICEfaces, portlets are treated as page fragments and so the logic for enhancing the <head> is never run.

        Issue Links

          Activity

          Hide
          Deryk Sinotte added a comment -

          I did notice in the NormalModeSerializer the following snippet:

          if (isFragment(requestMap)) {
          if (log.isDebugEnabled())

          { log.debug("treating request as a fragment"); }

          Node body = DOMUtils.getChildByNodeName(
          document.getDocumentElement(), "body");
          if (null != body)

          { //insert a containing element for bridge anchoring writer.write("<div>\n"); //We need to include, for now, ICE_EXTRAS all the time to //ensure that it is available. writer.write(makeScriptEntry(JavascriptContext.ICE_BRIDGE)); writer.write(makeScriptEntry(JavascriptContext.ICE_EXTRAS)); writer.write(DOMUtils.childrenToString(body)); writer.write("</div>\n"); }

          This does get run in portlets (which are basically treated as fragments). So I added this:

          String[] jsLibs = JavascriptContext.getIncludedLibs(context);
          for (int i = 0; i < jsLibs.length; i++)

          { String jsLib = jsLibs[i]; writer.write(makeScriptEntry(jsLib)); }

          Which seemed to get the Google components working as that is how they add the script library. But our Rich Text Component seems to do something else (not using the JavaScriptContext).

          Show
          Deryk Sinotte added a comment - I did notice in the NormalModeSerializer the following snippet: if (isFragment(requestMap)) { if (log.isDebugEnabled()) { log.debug("treating request as a fragment"); } Node body = DOMUtils.getChildByNodeName( document.getDocumentElement(), "body"); if (null != body) { //insert a containing element for bridge anchoring writer.write("<div>\n"); //We need to include, for now, ICE_EXTRAS all the time to //ensure that it is available. writer.write(makeScriptEntry(JavascriptContext.ICE_BRIDGE)); writer.write(makeScriptEntry(JavascriptContext.ICE_EXTRAS)); writer.write(DOMUtils.childrenToString(body)); writer.write("</div>\n"); } This does get run in portlets (which are basically treated as fragments). So I added this: String[] jsLibs = JavascriptContext.getIncludedLibs(context); for (int i = 0; i < jsLibs.length; i++) { String jsLib = jsLibs[i]; writer.write(makeScriptEntry(jsLib)); } Which seemed to get the Google components working as that is how they add the script library. But our Rich Text Component seems to do something else (not using the JavaScriptContext).
          Hide
          Mircea Toma added a comment -

          Insert page references directly into the document.

          Show
          Mircea Toma added a comment - Insert page references directly into the document.
          Hide
          Deryk Sinotte added a comment -

          There are still some issues. The Rich Text Editor appears to work but it uses a slightly different mechanism to inject it's scripts. The Google Map components use the JavaScriptContext API and the libraries are not being added. Re-opening.

          Show
          Deryk Sinotte added a comment - There are still some issues. The Rich Text Editor appears to work but it uses a slightly different mechanism to inject it's scripts. The Google Map components use the JavaScriptContext API and the libraries are not being added. Re-opening.
          Hide
          Deryk Sinotte added a comment -

          The code in the DOMResponseWriter for adding the component-specific libraries is making a conditional check before executing the code. The check fails in a portlet environment. Ive checked with Mircea and it seems that the conditional logic is no longer required. I'll remove it, test, and check it in if everything works out.

          Show
          Deryk Sinotte added a comment - The code in the DOMResponseWriter for adding the component-specific libraries is making a conditional check before executing the code. The check fails in a portlet environment. Ive checked with Mircea and it seems that the conditional logic is no longer required. I'll remove it, test, and check it in if everything works out.
          Hide
          Deryk Sinotte added a comment -

          Looks like does that trick. The revision has been checked in. Resolving as fixed.

          Show
          Deryk Sinotte added a comment - Looks like does that trick. The revision has been checked in. Resolving as fixed.
          Hide
          Niels Frydenholm added a comment -

          I have a problem with libraries not being loaded in a portlet after navigation.
          See this post http://www.icefaces.org/JForum/posts/list/0/12161.page#48507

          I think it is related to this issue.

          Show
          Niels Frydenholm added a comment - I have a problem with libraries not being loaded in a portlet after navigation. See this post http://www.icefaces.org/JForum/posts/list/0/12161.page#48507 I think it is related to this issue.
          Hide
          Juan Villanueva added a comment -

          Can somebody show me the code changed in DOMresponseWriter for the issue with Gmap?

          Thanks

          Show
          Juan Villanueva added a comment - Can somebody show me the code changed in DOMresponseWriter for the issue with Gmap? Thanks

            People

            • Assignee:
              Unassigned
              Reporter:
              Deryk Sinotte
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: