From 9033b1f4d9ff044a8aeb9a95dbb9dddc9728a83d Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 4 Sep 2014 15:56:06 -0400 Subject: [PATCH] Refine check for use of MyFaces Issue: SWF-1641 --- .../faces/webflow/FlowRenderKit.java | 2 +- .../faces/webflow/JsfRuntimeInformation.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java index 74ea4144..7b97222c 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowRenderKit.java @@ -44,7 +44,7 @@ public class FlowRenderKit extends RenderKitWrapper { } private ResponseStateManager initResponseStateManager(ResponseStateManager wrapped) { - if (!JsfRuntimeInformation.isMyFacesPresent()) { + if (!JsfRuntimeInformation.isMyFacesPresent() && !JsfRuntimeInformation.isMyFacesInUse()) { return new FlowResponseStateManager(wrapped); } Constructor constructor; diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java index da480aba..1011099d 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfRuntimeInformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.faces.webflow; +import javax.faces.FactoryFinder; import javax.faces.context.FacesContext; import org.springframework.util.Assert; @@ -62,6 +63,8 @@ public class JsfRuntimeInformation { private static final boolean myFacesPresent = ClassUtils.isPresent("org.apache.myfaces.webapp.MyFacesServlet", CLASS_LOADER); + private static final boolean myFacesInUse = checkMyFacesContextFactory(); + private static boolean portletPresent = ClassUtils.isPresent("javax.portlet.Portlet", CLASS_LOADER); private static boolean springPortletPresent = ClassUtils.isPresent("org.springframework.web.portlet.DispatcherPortlet", CLASS_LOADER); @@ -78,6 +81,19 @@ public class JsfRuntimeInformation { } else { jsfVersion = JSF_11; } + + } + + private static boolean checkMyFacesContextFactory() { + ClassLoader classLoader = JsfUtils.class.getClassLoader(); + try { + Class clazz = classLoader.loadClass("org.apache.myfaces.context.FacesContextFactoryImpl"); + Object factory = FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); + return clazz.isInstance(factory); + } + catch (Throwable ex) { + return false; + } } public static boolean isAtLeastJsf22() { @@ -116,6 +132,10 @@ public class JsfRuntimeInformation { return myFacesPresent; } + public static boolean isMyFacesInUse() { + return myFacesInUse; + } + /** * Determines if the container has support for portlets and if Spring MVC portlet support is available *