myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <...@myfaces.apache.org>
Subject [jira] [Commented] (MYFACES-3659) Conditional include of scripts and stylesheets
Date Tue, 11 Dec 2012 02:29:21 GMT

    [ https://issues.apache.org/jira/browse/MYFACES-3659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13528621#comment-13528621
] 

Leonardo Uribe commented on MYFACES-3659:
-----------------------------------------

First of all, set this web config param:

org.apache.myfaces.STRICT_JSF_2_REFRESH_TARGET_AJAX

to true. See: http://myfaces.apache.org/core21/myfaces-impl/webconfig.html#org_apache_myfaces_STRICT_JSF_2_REFRESH_TARGET_AJAX

Note this option does not play well with other libraries that overrides the default partial
response writer.

Related issues: MYFACES-3630, MYFACES-3462, MYFACES-3367, MYFACES-3106

I think the behavior described is expected, because you can't really remove a js file from
memory once loaded, unless you reload the whole page.

The code that is in place in myfaces core is for detect when a dynamic part requires some
resources and add them in ajax operations. For example, if you have a collapsible panel bound
to an c:if block, the idea is when is set to true, detect the addition of the resource and
force submit head or body fragment rendering.

Set a "transient" just works for the server side, but on the client the resource is not unloaded,
so it does not have any effect.

The ordering of the resources is only respected once the page is loaded. It does not matter
if X.js is set in the header before of after jQuery in an ajax refresh, because once the page
is loaded, in theory jQuery is set on top, but note JSF does not make any assumption about
the loading order of javascript files.

                
> Conditional include of scripts and stylesheets 
> -----------------------------------------------
>
>                 Key: MYFACES-3659
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3659
>             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: http://www.atlassian.com/software/jira

Mime
View raw message