From f860d9e17a6d818f9531ad1090cb818f174d6ef6 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 6 Aug 2015 15:51:05 -0400 Subject: [PATCH] Improve isMyFacesInUse check The check now accounts for the possibility of a FacesContextFactory being wrapped. Issue: SWF-1650 --- .../faces/webflow/JsfRuntimeInformation.java | 9 +++++++-- .../context/portlet/PortletFacesContextFactory.java | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) 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 379b9f2c..66d516a0 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 @@ -16,6 +16,7 @@ package org.springframework.faces.webflow; +import javax.faces.FacesWrapper; import javax.faces.FactoryFinder; import javax.faces.context.FacesContext; @@ -25,7 +26,8 @@ import org.springframework.util.ReflectionUtils; import org.springframework.webflow.execution.RequestContext; /** - * Helper class to provide information about the JSF runtime environment such as JSF version and implementation. + * Helper class to provide information about the JSF runtime environment such as + * JSF version and implementation. * * @author Rossen Stoyanchev * @author Phillip Webb @@ -89,7 +91,10 @@ public class JsfRuntimeInformation { try { Class clazz = classLoader.loadClass("org.apache.myfaces.context.FacesContextFactoryImpl"); Object factory = FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); - return clazz.isInstance(factory); + while (!clazz.isInstance(factory) && factory instanceof FacesWrapper) { + factory = ((FacesWrapper) factory).getWrapped(); + } + return (factory != null && clazz.isInstance(factory)); } catch (Throwable ex) { return false; diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextFactory.java b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextFactory.java index 2896ff23..99033c01 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextFactory.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/context/portlet/PortletFacesContextFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2015 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. @@ -29,6 +29,7 @@ import org.springframework.faces.webflow.JsfRuntimeInformation; /** * {@link FacesContextFactory} to support portlet environments. * @author Phillip Webb + * @author Rossen Stoyanchev */ public class PortletFacesContextFactory extends FacesContextFactory { @@ -38,6 +39,12 @@ public class PortletFacesContextFactory extends FacesContextFactory { this.factory = factory; } + + @Override + public FacesContextFactory getWrapped() { + return this.factory; + } + @Override public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle) throws FacesException {