Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-3659

Conditional include of scripts and stylesheets

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.6
    • 2.0.17, 2.1.11
    • None
    • None
    • MyFaces 2.1.6, Tomahawk20 1.1.11

    Description

      I am inserting a script 'X.js' dependent on a condition (c:if). The default case is to include it. If I change the underlying value within an action so that the condition evaluates to false, the script is still included. Also after any other following action.

      Using F5 in Firefox the page is now rendered without the script.

      The script 'X.js' was added to the view root and is never 'forgot' or removed. It is the same if the script is included in a composite component. In that case I even observed that the order of the scripts changes and the script 'X.js' is included before other basic scripts like jQuery on which 'X.js' depends.


      <h:form id="form">
      <c:set var="sessionScope" value="#

      {facesContext.externalContext.sessionMap}

      " />

      <h:commandButton value="deactivate"
      rendered="#

      {empty sessionScope.__isActive_ or sessionScope.__isActive_}">
      <f:setPropertyActionListener target="#{sessionScope.__isActive_}" value="#{false}" />
      </h:commandButton>
      <h:commandButton value="activate"
      rendered="#{not empty sessionScope.__isActive_ and not sessionScope.__isActive_}">
      <f:setPropertyActionListener target="#{sessionScope.__isActive_}" value="#{true}" />
      </h:commandButton>

      <h:commandButton value="do nothing" />

      <h:outputScript library="js" name="jQuery.js" target="body" />

      <c:if test="#{empty sessionScope.__isActive_ or sessionScope.__isActive_}

      ">
      BLA
      <h:outputScript library="js" name="X.js" target="body" />
      </c:if>
      </h:form>


      Am I doing something wrong? Is there another (or better) way to include scripts conditionally?

      (
      If I change 'HtmlOutputScriptHandler' to set the script transient, it works in the first glance, but I don't know the impact...

      @Override
      public void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent) {
      super.onComponentPopulated(ctx, c, parent);
      c.setTransient(true);
      }
      )

      Attachments

        1. patch-MYFACES-3659.diff
          18 kB
          dennis hoersch
        2. patch-MYFACES-3659.zip
          20 kB
          dennis hoersch
        3. MYFACES-3659_2.diff
          7 kB
          dennis hoersch
        4. MYFACES-3659_2.zip
          19 kB
          dennis hoersch
        5. MYFACES-3659-3.patch
          7 kB
          Leonardo Uribe
        6. MYFACES-3659_3.diff
          8 kB
          dennis hoersch
        7. MYFACES-3659-4.patch
          8 kB
          Leonardo Uribe
        8. test-MYFACES-3659.zip
          2 kB
          dennis hoersch

        Activity

          People

            lu4242 Leonardo Uribe
            hoersch dennis hoersch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: