Return-Path: X-Original-To: apmail-myfaces-dev-archive@www.apache.org Delivered-To: apmail-myfaces-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 406B3E49A for ; Mon, 17 Dec 2012 19:46:47 +0000 (UTC) Received: (qmail 3207 invoked by uid 500); 17 Dec 2012 19:46:46 -0000 Delivered-To: apmail-myfaces-dev-archive@myfaces.apache.org Received: (qmail 3111 invoked by uid 500); 17 Dec 2012 19:46:46 -0000 Mailing-List: contact dev-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list dev@myfaces.apache.org Received: (qmail 2651 invoked by uid 99); 17 Dec 2012 19:46:46 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Dec 2012 19:46:46 +0000 Date: Mon, 17 Dec 2012 19:46:46 +0000 (UTC) From: "dennis hoersch (JIRA)" To: dev@myfaces.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (MYFACES-3659) Conditional include of scripts and stylesheets MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MYFACES-3659?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13534222#comment-13534222 ] dennis hoersch commented on MYFACES-3659: ----------------------------------------- Thanks for your reply. > 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. Do I understand it right: To 'unload' (or 'load' new) resources in ajax requests the hint 'requestViewContext.setRenderTarget(target, true)' should be set? And then, for example if the isRenderTarget(head) flag is set, the whole head will be encoded in the partial response? If so, one solution might be the 'transient' thing and to check during the ajax request whether there is any difference in the list if component resources to the one of the previous request and set the appropriate 'isRenderTarget()' flag. Some components add resources on 'PostAddToViewEvent' or 'PreRenderViewAddResourceEvent'. So the checking might be directly before creating the (ajax) response. The best place I found so far is in UIViewRoot.encodeAll(): --- @Override public void encodeAll(FacesContext context) throws IOException { checkComponentResourcesForReRendering(context, "head"); checkComponentResourcesForReRendering(context, "body"); checkComponentResourcesForReRendering(context, "form"); super.encodeAll(context); } private void checkComponentResourcesForReRendering(FacesContext context, String target) { String attributeName = "_OLD_COMPONENT_RESOURCES_" + target; List resources = getComponentResources(context, target); String newResourcesMarker = resourcesToString(resources); if (context.getPartialViewContext().isAjaxRequest()) { String oldResourcesMarker = (String) getAttributes().get(attributeName); if (oldResourcesMarker != null && !newResourcesMarker.equals(oldResourcesMarker)) { if (!ExternalContextUtils.isPortlet(context.getExternalContext()) && !context.getAttributes().containsKey(StateManager.IS_BUILDING_INITIAL_STATE) && MyfacesConfig.getCurrentInstance(context.getExternalContext()).isStrictJsf2RefreshTargetAjax()) { //!(component.getParent() instanceof ComponentResourceContainer) RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(context); requestViewContext.setRenderTarget(target, true); } } } getAttributes().put(attributeName, newResourcesMarker); } private String resourcesToString(List resources) { StringBuilder sb = new StringBuilder(); for (UIComponent resource : resources) { sb.append(resource.getAttributes().get("library")).append(":").append(resource.getAttributes().get("name")).append(";"); } return sb.toString(); } --- Setting the flag in 'HtmlStylesheetRenderer' and 'HtmlScriptRenderer' could be removed than. > 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. > ---- > > > > rendered="#{empty sessionScope.__isActive_ or sessionScope.__isActive_}"> > > > rendered="#{not empty sessionScope.__isActive_ and not sessionScope.__isActive_}"> > > > > > > > > > BLA > > > > ---- > 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