lofwyr14 closed pull request #11: Tobago 1870 URL: https://github.com/apache/myfaces-tobago/pull/11
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 8a027d839..76be5df51 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 @@ -27,6 +27,8 @@ import javax.faces.event.PostAddToViewEvent; import javax.faces.event.PreRenderViewEvent; +import org.apache.myfaces.tobago.util.FacesVersion; + @ListenerFor(systemEventClass = PostAddToViewEvent.class) public abstract class AbstractUIMeta extends UIComponentBase { @@ -36,18 +38,27 @@ public void processEvent(final ComponentSystemEvent event) { super.processEvent(event); if (event instanceof PreRenderViewEvent) { - final FacesContext facesContext = getFacesContext(); - final UIViewRoot root = facesContext.getViewRoot(); - root.addComponentResource(facesContext, this); + addComponentResource(); } 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); + if (FacesVersion.supports21() || !FacesVersion.isMyfaces()) { + // 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 + // NOTE: PreRenderViewEvent can not used in myfaces prior 2.0.3 using PostAddToView for all myfaces 2.0 versions + getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } else { + addComponentResource(); + } } } + private void addComponentResource() { + final FacesContext facesContext = getFacesContext(); + final UIViewRoot root = facesContext.getViewRoot(); + root.addComponentResource(facesContext, this); + } + public abstract String getCharset(); public abstract String getHttpEquiv(); 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 b53bfb7bb..5d289017e 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 @@ -27,6 +27,8 @@ import javax.faces.event.PostAddToViewEvent; import javax.faces.event.PreRenderViewEvent; +import org.apache.myfaces.tobago.util.FacesVersion; + /** * {@link org.apache.myfaces.tobago.internal.taglib.component.ScriptTagDeclaration} * @@ -41,17 +43,26 @@ public void processEvent(final ComponentSystemEvent event) { super.processEvent(event); if (event instanceof PreRenderViewEvent) { - final FacesContext facesContext = getFacesContext(); - final UIViewRoot root = facesContext.getViewRoot(); - root.addComponentResource(facesContext, this); + addComponentResource(); } 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); + if (FacesVersion.supports21() || !FacesVersion.isMyfaces()) { + // 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 + // NOTE: PreRenderViewEvent can not used in myfaces prior 2.0.3 using PostAddToView for all myfaces 2.0 versions + getFacesContext().getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } else { + addComponentResource(); + } } } + private void addComponentResource() { + final FacesContext facesContext = getFacesContext(); + final UIViewRoot root = facesContext.getViewRoot(); + root.addComponentResource(facesContext, 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 5f5876a2b..0a3b52696 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 @@ -29,6 +29,7 @@ import org.apache.myfaces.tobago.layout.Position; import org.apache.myfaces.tobago.layout.TextAlign; import org.apache.myfaces.tobago.renderkit.css.CustomClass; +import org.apache.myfaces.tobago.util.FacesVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,12 +65,18 @@ public void processEvent(final ComponentSystemEvent event) { 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); + // 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 + // NOTE: PreRenderViewEvent can not used in myfaces prior 2.0.3 using PostAddToView for all myfaces 2.0 versions + if (FacesVersion.supports21() || !FacesVersion.isMyfaces()) { + facesContext.getViewRoot().subscribeToEvent(PreRenderViewEvent.class, this); + } else { + final UIViewRoot root = facesContext.getViewRoot(); + root.addComponentResource(facesContext, this); + } } // attribute customClass final ValueExpression valueExpression = getValueExpression(Attributes.customClass.getName()); ---------------------------------------------------------------- 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