Jetspeed 2
  1. Jetspeed 2
  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.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1
    • Fix Version/s: 2.2.2
    • Component/s: None
    • Labels:
      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.

        Activity

        Hide
        Woonsan Ko added a comment -

        How about adding a jetspeed specific portlet metadata for this kind of portlet?
        For example, if a portlet has a jetspeed specific metadata (e.g., "jetui.refresh.page.on.add.portlet = true"), then the JetUI could just refresh the page after adding the portlet fragment. This will solve the problem with the current hybrid JetUI rendering engine.

        Show
        Woonsan Ko added a comment - How about adding a jetspeed specific portlet metadata for this kind of portlet? For example, if a portlet has a jetspeed specific metadata (e.g., "jetui.refresh.page.on.add.portlet = true"), then the JetUI could just refresh the page after adding the portlet fragment. This will solve the problem with the current hybrid JetUI rendering engine.
        Hide
        Woonsan Ko added a comment -

        I found this problem happened when adding WebWidget portlet, too.
        Because the script of a widget source is not executed when added dynamically, it displays nothing at first.
        After a page refreshment, the widget starts normal displaying.

        Show
        Woonsan Ko added a comment - I found this problem happened when adding WebWidget portlet, too. Because the script of a widget source is not executed when added dynamically, it displays nothing at first. After a page refreshment, the widget starts normal displaying.
        Hide
        Woonsan Ko added a comment -

        Fixed.

        If a portlet definition has "jetui.refresh.page.on.add.portlet" metadata with value, "true", then the page will be refreshed when adding the portlet with toolbox portlet.

        Show
        Woonsan Ko added a comment - Fixed. If a portlet definition has "jetui.refresh.page.on.add.portlet" metadata with value, "true", then the page will be refreshed when adding the portlet with toolbox portlet.

          People

          • Assignee:
            Woonsan Ko
            Reporter:
            Woonsan Ko
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development