[
https://issues.apache.org/jira/browse/MYFACES-3659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13535372#comment-13535372
]
Leonardo Uribe commented on MYFACES-3659:
-----------------------------------------
I have checked the patch and I think it goes in the right direction. Just we
need to polish some observations.
- Mark relocated resources
Yes, it is a good idea of introduce some code in ComponentTagHandlerDelegate to
deal with components implementing RelocatableResourceHandler. I know the
solution works because the relocation occur from leaves to root, but that will
not work in other cases. Long time ago, it was discussed that component
relocation without use the template engine is a bad idea, so MyFaces composite
component implementation was fully changed to avoid those tricks, and the only
valid case that remains is h:outputScript/h:outputStylesheet. I would like a
more general solution, like for example, so an special mark/delete for
RelocatableResourceHandler components that is only executed just before the
end, specifically inside DefaultFacelet when finalizeForDeletion() method is
called. It does not matter if it requires a call to visitTree with
SKIP_ITERATION hint enabled, because you can end the visit anytime (once all
relocated components are found), and the facets are always scanned first.
In other side there is a consideration here from performance perspective.
mark/delete algorithm has been designed to be as fast as possible and the
intention is keep it in that way. The additional else if (fc instanceof
ComponentResourceContainer) in FaceletCompositionContextImpl impose some
overhead that can be fixed just moving the code to DefaultFacelet.
Also, another thing we need to take a look is how to avoid manipulate the
component attribute map for mark/delete. The reason is that let some null spots
into the state and the objective is have zero state. A trick like the one
proposed with IS_CURRENTLY_ADDED_MARKER let that kind of spots without notice.
For this case, it does not matter if that code is called two or more times,
because the effect is the same.
Set renderTarget flag for resources removed is controversial. For one side, it
is not really necessary because for example once loaded a js file it cannot be
unloaded, but the same is not true for css resources. I suppose a config param
to enable/disable this behavior is preferred.
> 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
> Attachments: patch-MYFACES-3659.diff, patch-MYFACES-3659.zip
>
>
> 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