Uploaded image for project: 'Jetspeed 2 (Retired)'
  1. Jetspeed 2 (Retired)
  2. JS2-1194

Some Portlets which contain 'document.write()' js calls (e.g. GWT-based portlet) is not rendered at first after adding the portlet.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.2.1
    • 2.2.2
    • None
    • None

    Description

      This issue has been known for long time for client-side rendering modules, so there were some solutions.
      However, we don't have any solution in JetUI yet.
      GWT based portlet application should contain a js file, "...nocache.js", which contains "document.write()" calls. This call causes the weird page status after adding the portlet.

      By the way, the Jetspeed-2 Desktop had a solution for this problem like the following:

      • It retrieves the portlet rendered content from the /portlet pipeline.
      • It inspects the content whether the content has <script> tags.
      • If it contains a script tag with src attribute, it retrieves the real source content.
      • It inspects each code line and replaces with the following rules:
        a) Replace "addEventListener|attachEvent" by a custom JS2 code:
        /\b([a-z_A-Z$]\w*)\s*\.\s*(addEventListener|attachEvent)\s*(/
        ==> "jetspeed.postload_" + methodNm + "(" + nodeRef + "," + script.substr(match.index + match[0].length)
        b) Replace "document.write()" by a custom JS2 code:
        /\b(document\s*.\s*write(ln)?)\s*(/
        ==> "jetspeed.postload_docwrite(" + script.substr(match.index + match[0].length)
        c) Replace "location.href = ..." by a custom JS2 code:
        /(;\s|\s+)([a-z_A-Z$][\w.])\s\.\s*(URL\s*|(location\s*(\.\s*href\s*) {0,1}

        ))=\s*(("[^"]"|'[^']'|[^;])[^;]*)/
        ==> "jetspeed.setdoclocation(" + match[2] + ', "' + memberExpr + '", (' + match[6] + '))' + script.substr(match.index + match[0].length)

      • References: PortletWindow.src.js and core.src.js, APA-5, JS2-1063.

      However, the solution provided by JS2 desktop has some caveats:

      • Looks too hacky.
      • If the script uses a different variable name for document, the current code could not detect it. (GWT does this: l = document; )

      By the way, we could recommend some best practices for portlet development instead of fixing this problem inside JS2:

      • A Portlet should not use "document.write()" calls; Instead, it is recommended to use Portlet 2.0 head contribution where possible.
      • A Portlet should not use "addEventListener|attachEvent" calls; Instead, it is recommended to use higher level frameworks such as YUI3.
      • It is not recommended for a Portlet to use "location.href = ...;".

      Anyway, I don't have a clear idea to solve this problem yet.

      Attachments

        Activity

          People

            woon_san Woonsan Ko
            woon_san Woonsan Ko
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: