bohmber closed pull request #10: Tobago-1870 URL: https://github.com/apache/myfaces-tobago/pull/10
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java index 2edf4b9c5..8a027d839 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIMeta.java @@ -25,15 +25,27 @@ import javax.faces.event.ComponentSystemEvent; import javax.faces.event.ListenerFor; import javax.faces.event.PostAddToViewEvent; +import javax.faces.event.PreRenderViewEvent; @ListenerFor(systemEventClass = PostAddToViewEvent.class) public abstract class AbstractUIMeta extends UIComponentBase { @Override public void processEvent(final ComponentSystemEvent event) { - final FacesContext facesContext = getFacesContext(); - final UIViewRoot root = facesContext.getViewRoot(); - root.addComponentResource(facesContext, this); + + super.processEvent(event); + + if (event instanceof PreRenderViewEvent) { + final FacesContext facesContext = getFacesContext(); + final UIViewRoot root = facesContext.getViewRoot(); + root.addComponentResource(facesContext, this); + } else if (event instanceof PostAddToViewEvent) { + // MyFaces core is removing the component resources in head if the view will be recreated before rendering. + // The view will be recreated because of expressions. For example expressins in the ui:include src attribute + // The PostAddToViewEvent will not be broadcasted in this case again. + // A subscription to the PreRenderViewEvent avoids this problem + getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } } public abstract String getCharset(); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIScript.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIScript.java index 1ed52bb9a..b53bfb7bb 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIScript.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIScript.java @@ -25,6 +25,7 @@ import javax.faces.event.ComponentSystemEvent; import javax.faces.event.ListenerFor; import javax.faces.event.PostAddToViewEvent; +import javax.faces.event.PreRenderViewEvent; /** * {@link org.apache.myfaces.tobago.internal.taglib.component.ScriptTagDeclaration} @@ -36,9 +37,20 @@ @Override public void processEvent(final ComponentSystemEvent event) { - final FacesContext facesContext = getFacesContext(); - final UIViewRoot root = facesContext.getViewRoot(); - root.addComponentResource(facesContext, this); + + super.processEvent(event); + + if (event instanceof PreRenderViewEvent) { + final FacesContext facesContext = getFacesContext(); + final UIViewRoot root = facesContext.getViewRoot(); + root.addComponentResource(facesContext, this); + } else if (event instanceof PostAddToViewEvent) { + // MyFaces core is removing the component resources in head if the view will be recreated before rendering. + // The view will be recreated because of expressions. For example expressins in the ui:include src attribute + // The PostAddToViewEvent will not be broadcasted in this case again. + // A subscription to the PreRenderViewEvent avoids this problem + getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } } public abstract String getFile(); diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIStyle.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIStyle.java index ea7d99a69..5f5876a2b 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIStyle.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIStyle.java @@ -40,6 +40,7 @@ import javax.faces.event.ComponentSystemEvent; import javax.faces.event.ListenerFor; import javax.faces.event.PostAddToViewEvent; +import javax.faces.event.PreRenderViewEvent; /** * {@link org.apache.myfaces.tobago.internal.taglib.component.StyleTagDeclaration} @@ -53,17 +54,23 @@ @Override public void processEvent(final ComponentSystemEvent event) { - + super.processEvent(event); final FacesContext facesContext = getFacesContext(); - if (event instanceof PostAddToViewEvent) { - + if (event instanceof PreRenderViewEvent) { // attribute file if (StringUtils.isNotBlank(getFile())) { final UIViewRoot root = facesContext.getViewRoot(); root.addComponentResource(facesContext, this); } - + } else if (event instanceof PostAddToViewEvent) { + // MyFaces core is removing the component resources in head if the view will be recreated before rendering. + // The view will be recreated because of expressions. For example expressins in the ui:include src attribute + // The PostAddToViewEvent will not be broadcasted in this case again. + // A subscription to the PreRenderViewEvent avoids this problem + if (StringUtils.isNotBlank(getFile())) { + facesContext.getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } // attribute customClass final ValueExpression valueExpression = getValueExpression(Attributes.customClass.getName()); if (valueExpression != null) { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services