Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-2974

Some children of jsf <head> components are not written to the response

    Details

      Description

      This bug causes all children of h:head to not be rendered except outputStylesheet and outputScript components (ex: <script>, <style>, link, meta etc. fail to render).

      Steps to reproduce:

      1. Add the following code to the <h:head> tag of the jsf-applicant-portlet's portletViewMode.xhtml:
         <script type="text/javascript" src="https://rawgit.com/stiemannkj1/d3fdd05557c0df32bf1c1e7e45f51c9c/raw/9b2bd1df7d74b4c08efe63b0a42684fba0c009f9/test-js.js"></script>
        
      2. Deploy the portlet and navigate to it.

      If the bug still exists, the portlet will render, no alert with appear, and the <script> markup will not appear in the browser.

      If the bug is fixed, the <script> markup will appear in the browser, and an alert will appear with the following text:

      test-js.js loaded

      Workaround

      To workaround this issue, you can create a composite component with a name attribute. The name must end in either "css" or "js" and should probably be unique per view to ensure that it is always loaded. For example to render scripts like the one mentioned above in the head section, create the following resources/workaround/headElements.xhtml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <ui:component xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
          xmlns:cc="http://xmlns.jcp.org/jsf/composite" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd">
      
          <!-- Workaround for https://issues.liferay.com/browse/FACES-2974 -->
          <cc:interface>
              <cc:attribute name="name" required="true" />
          </cc:interface>
      
          <cc:implementation>
              <cc:insertChildren />
          </cc:implementation>
      
      </ui:component>
      

      To use this component with the script mentioned above:

      <workaround:headElements name="#{view.viewId}.js">
          <script type="text/javascript"
          src="https://rawgit.com/stiemannkj1/d3fdd05557c0df32bf1c1e7e45f51c9c/raw/9b2bd1df7d74b4c08efe63b0a42684fba0c009f9/test-js.js"></script>
      </workaround:headElements>
      

        Activity

        Hide
        kyle.stiemann Kyle Stiemann added a comment -

        The fix for this issue would likely be to call through to super.encodeChildren() (which is what we did in 4.2.5-ga6). However we can only call through to the super impl when we don't need to relocate elements to the <h:body> tag (which needs to happen on occasion).

        It is unfortunately not possible to differentiate between non-JSF tags (such as <script> and <meta>) in a JSF renderer, so we should probably relocate all <h:head> elements to the body (this may cause invalid markup like <meta> tags in the <body>). I suppose we could suppress certain elements in the <h:body> ResponseWriter if we wanted to. We could even temporarily suppress those elements only when relocating them so that we provide the developer with maximum flexibility.

        I'd opt for #2 since we already relocate styles to the <body> and accept invalid markup in that case.

        Show
        kyle.stiemann Kyle Stiemann added a comment - The fix for this issue would likely be to call through to super.encodeChildren() (which is what we did in 4.2.5-ga6 ). However we can only call through to the super impl when we don't need to relocate elements to the <h:body> tag (which needs to happen on occasion). It is unfortunately not possible to differentiate between non-JSF tags (such as <script> and <meta> ) in a JSF renderer, so we should probably relocate all <h:head> elements to the body (this may cause invalid markup like <meta> tags in the <body> ). I suppose we could suppress certain elements in the <h:body> ResponseWriter if we wanted to. We could even temporarily suppress those elements only when relocating them so that we provide the developer with maximum flexibility. I'd opt for #2 since we already relocate styles to the <body> and accept invalid markup in that case.
        Hide
        kyle.stiemann Kyle Stiemann added a comment - - edited

        According to the HTML5 spec, it seems like the only elements we would want to not migrate to the body would be title, base, and meta.

        https://www.w3.org/TR/html5/dom.html#metadata-content-0
        https://www.w3.org/TR/html5/document-metadata.html#the-head-element

        Show
        kyle.stiemann Kyle Stiemann added a comment - - edited According to the HTML5 spec, it seems like the only elements we would want to not migrate to the body would be title , base , and meta . https://www.w3.org/TR/html5/dom.html#metadata-content-0 https://www.w3.org/TR/html5/document-metadata.html#the-head-element
        Hide
        kyle.stiemann Kyle Stiemann added a comment - - edited
        Show
        kyle.stiemann Kyle Stiemann added a comment - - edited This issue was first discovered in the forums: https://web.liferay.com/community/forums/-/message_boards/message/83292004

          People

          • Assignee:
            kyle.stiemann Kyle Stiemann
            Reporter:
            kyle.stiemann Kyle Stiemann
            Participants of an Issue:
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development

                Subcomponents