Fix JSF < 2.2 compatibility issues
Issue: SWF-1634
This commit is contained in:
@@ -90,7 +90,7 @@ public class FlowFacesContext extends FacesContext {
|
||||
this.context = context;
|
||||
this.delegate = delegate;
|
||||
this.messageDelegate = new FlowFacesContextMessageDelegate(context);
|
||||
this.externalContext = new FlowExternalContext(delegate.getExternalContext());
|
||||
this.externalContext = new FlowExternalContext(delegate.getExternalContext(), context);
|
||||
setCurrentInstance(this);
|
||||
}
|
||||
|
||||
@@ -218,12 +218,15 @@ public class FlowFacesContext extends FacesContext {
|
||||
return messageDelegate;
|
||||
}
|
||||
|
||||
protected class FlowExternalContext extends ExternalContextWrapper {
|
||||
protected static class FlowExternalContext extends ExternalContextWrapper {
|
||||
|
||||
private static final String CUSTOM_RESPONSE = "customResponse";
|
||||
|
||||
public FlowExternalContext(ExternalContext delegate) {
|
||||
private RequestContext context;
|
||||
|
||||
public FlowExternalContext(ExternalContext delegate, RequestContext context) {
|
||||
super(delegate);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Object getResponse() {
|
||||
|
||||
@@ -44,15 +44,16 @@ import org.springframework.webflow.execution.RequestContext;
|
||||
*/
|
||||
public class Jsf2FlowFacesContext extends FlowFacesContext {
|
||||
|
||||
private ExternalContext externalContext;
|
||||
private final ExternalContext externalContext;
|
||||
|
||||
private final PartialViewContext partialViewContext;
|
||||
|
||||
private PartialViewContext partialViewContext;
|
||||
|
||||
public Jsf2FlowFacesContext(RequestContext context, FacesContext delegate) {
|
||||
super(context, delegate);
|
||||
|
||||
this.externalContext = new Jsf2FlowExternalContext(getDelegate().getExternalContext());
|
||||
|
||||
this.externalContext = (JsfRuntimeInformation.isAtLeastJsf22() ?
|
||||
new Jsf22FlowExternalContext(getDelegate().getExternalContext(), context) :
|
||||
new Jsf2FlowExternalContext(getDelegate().getExternalContext(), context));
|
||||
PartialViewContextFactory factory = (PartialViewContextFactory) FactoryFinder
|
||||
.getFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY);
|
||||
PartialViewContext partialViewContextDelegate = factory.getPartialViewContext(this);
|
||||
@@ -138,12 +139,12 @@ public class Jsf2FlowFacesContext extends FlowFacesContext {
|
||||
return getDelegate().isReleased();
|
||||
}
|
||||
|
||||
protected class Jsf2FlowExternalContext extends FlowExternalContext {
|
||||
private static class Jsf2FlowExternalContext extends FlowExternalContext {
|
||||
|
||||
Log logger = LogFactory.getLog(FlowExternalContext.class);
|
||||
|
||||
public Jsf2FlowExternalContext(ExternalContext delegate) {
|
||||
super(delegate);
|
||||
public Jsf2FlowExternalContext(ExternalContext delegate, RequestContext context) {
|
||||
super(delegate, context);
|
||||
}
|
||||
|
||||
public void responseSendError(int statusCode, String message) throws IOException {
|
||||
@@ -267,6 +268,14 @@ public class Jsf2FlowFacesContext extends FlowFacesContext {
|
||||
delegate.setSessionMaxInactiveInterval(interval);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Jsf22FlowExternalContext extends FlowExternalContext {
|
||||
|
||||
public Jsf22FlowExternalContext(ExternalContext delegate, RequestContext context) {
|
||||
super(delegate, context);
|
||||
}
|
||||
|
||||
// --------------- JSF 2.2 Pass-through delegate methods ------------------//
|
||||
|
||||
public String getApplicationContextPath() {
|
||||
|
||||
@@ -37,13 +37,23 @@ public class JsfRuntimeInformation {
|
||||
/** JSF Version 2.0 */
|
||||
public static final int JSF_20 = 2;
|
||||
|
||||
/** JSF Version 2.1 */
|
||||
public static final int JSF_21 = 3;
|
||||
|
||||
/** JSF Version 2.2 */
|
||||
public static final int JSF_22 = 4;
|
||||
|
||||
private static final int jsfVersion;
|
||||
|
||||
private static final boolean myFacesPresent = ClassUtils.isPresent("org.apache.myfaces.webapp.MyFacesServlet",
|
||||
JsfUtils.class.getClassLoader());
|
||||
|
||||
static {
|
||||
if (ReflectionUtils.findMethod(FacesContext.class, "isPostback") != null) {
|
||||
if (ReflectionUtils.findMethod(FacesContext.class, "getResourceLibraryContracts") != null) {
|
||||
jsfVersion = JSF_22;
|
||||
} else if (ReflectionUtils.findMethod(FacesContext.class, "isReleased") != null) {
|
||||
jsfVersion = JSF_21;
|
||||
} else if (ReflectionUtils.findMethod(FacesContext.class, "isPostback") != null) {
|
||||
jsfVersion = JSF_20;
|
||||
} else if (ReflectionUtils.findMethod(FacesContext.class, "getELContext") != null) {
|
||||
jsfVersion = JSF_12;
|
||||
@@ -52,6 +62,14 @@ public class JsfRuntimeInformation {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAtLeastJsf22() {
|
||||
return jsfVersion >= JSF_22;
|
||||
}
|
||||
|
||||
public static boolean isAtLeastJsf21() {
|
||||
return jsfVersion >= JSF_21;
|
||||
}
|
||||
|
||||
public static boolean isAtLeastJsf20() {
|
||||
return jsfVersion >= JSF_20;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user