myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <>
Subject [jira] [Commented] (MYFACES-3659) Conditional include of scripts and stylesheets
Date Fri, 14 Dec 2012 02:32:12 GMT


Leonardo Uribe commented on MYFACES-3659:

I see. In theory what's happening is the mark/remove algorithm used by facelets for <c:if>
and other dynamic parts of the component tree controlled by facelets does not affect the components
under head,body,form or other component resource facets at UIViewRoot level.

In this case:

  <c:if test="#{empty sessionScope.__isActive_ or sessionScope.__isActive_}">
    <h:outputScript library="js" name="X.js" target="body" />

Once the component tree is built, BLA is inside c:if but h:outputScript was relocated under
body facet in UIViewRoot. In a refresh, BLA is removed, but h:outputScript is not because
mark/remove algorithm does not take into account components under those facets. 

The discussion related to implement this behavior is if it is worth to do it or not, because
it is not a bug "per se". The presence of the resource does not affect the underlying logic,
because it is "supposed" js or css resources are mutually exclusive. Note this is only a supposition
until this moment.

I suppose facelets algorithm can be improved to include an special mark/remove for relocated
components. The trick should be done in DefaultFacelet.apply method, but care must be taken
because a check should be included to indicate when the facelet is a top level one, and not
one consumed as a template (maybe the trick can be done through FaceletCompositionContext,
just a flag that is enabled by the first DefaultFacelet).

I have to say it, this issue has low priority to me in front of the work to do for JSF 2.2.
Help is welcome.
> Conditional include of scripts and stylesheets 
> -----------------------------------------------
>                 Key: MYFACES-3659
>                 URL:
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions: 2.1.6
>         Environment: MyFaces 2.1.6, Tomahawk20 1.1.11
>            Reporter: dennis hoersch
> 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);
> }
> )

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message