SWF-389 - Encapsulate the recommended default Web Flow configuration for a JSF environment.
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
public class FacesConfigNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("flow-builder-services", new FacesFlowBuilderServicesBeanDefinitionParser());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.springframework.faces.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.faces.expression.LegacyJSFELExpressionParser;
|
||||
import org.springframework.faces.model.converter.FacesConversionService;
|
||||
import org.springframework.faces.webflow.JsfViewFactoryCreator;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.webflow.core.expression.el.WebFlowELExpressionParser;
|
||||
import org.springframework.webflow.engine.builder.support.FlowBuilderServices;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class FacesFlowBuilderServicesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser implements
|
||||
BeanDefinitionParser {
|
||||
|
||||
private static final String ENABLE_MANAGED_BEANS_ATTRIBUTE = "enable-managed-beans";
|
||||
|
||||
private static final String EXPRESSION_PARSER_ATTRIBUTE = "expression-parser";
|
||||
|
||||
private static final String EXPRESSION_PARSER_PROPERTY = "expressionParser";
|
||||
|
||||
private static final String VIEW_FACTORY_CREATOR_ATTRIBUTE = "view-factory-creator";
|
||||
|
||||
private static final String VIEW_FACTORY_CREATOR_PROPERTY = "viewFactoryCreator";
|
||||
|
||||
private static final String CONVERSION_SERVICE_ATTRIBUTE = "conversion-service";
|
||||
|
||||
private static final String CONVERSION_SERVICE_PROPERTY = "conversionService";
|
||||
|
||||
protected Class getBeanClass(Element element) {
|
||||
return FlowBuilderServices.class;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, BeanDefinitionBuilder definitionBuilder) {
|
||||
boolean enableManagedBeans = parseEnableManagedBeans(element, definitionBuilder);
|
||||
if (!enableManagedBeans) {
|
||||
parseExpressionParser(element, definitionBuilder);
|
||||
}
|
||||
parseViewFactoryCreator(element, definitionBuilder);
|
||||
parseConversionService(element, definitionBuilder);
|
||||
}
|
||||
|
||||
private boolean parseEnableManagedBeans(Element element, BeanDefinitionBuilder definitionBuilder) {
|
||||
String enableManagedBeans = element.getAttribute(ENABLE_MANAGED_BEANS_ATTRIBUTE);
|
||||
if (StringUtils.hasText(enableManagedBeans)) {
|
||||
boolean enabled = Boolean.parseBoolean(enableManagedBeans);
|
||||
if (enabled) {
|
||||
definitionBuilder.addPropertyValue(EXPRESSION_PARSER_PROPERTY, new LegacyJSFELExpressionParser());
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void parseConversionService(Element element, BeanDefinitionBuilder definitionBuilder) {
|
||||
String conversionService = element.getAttribute(CONVERSION_SERVICE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(conversionService)) {
|
||||
definitionBuilder.addPropertyReference(CONVERSION_SERVICE_PROPERTY, conversionService);
|
||||
} else {
|
||||
definitionBuilder.addPropertyValue(CONVERSION_SERVICE_PROPERTY, new FacesConversionService());
|
||||
}
|
||||
}
|
||||
|
||||
private void parseViewFactoryCreator(Element element, BeanDefinitionBuilder definitionBuilder) {
|
||||
String viewFactoryCreator = element.getAttribute(VIEW_FACTORY_CREATOR_ATTRIBUTE);
|
||||
if (StringUtils.hasText(viewFactoryCreator)) {
|
||||
definitionBuilder.addPropertyReference(VIEW_FACTORY_CREATOR_PROPERTY, viewFactoryCreator);
|
||||
} else {
|
||||
definitionBuilder.addPropertyValue(VIEW_FACTORY_CREATOR_PROPERTY, new JsfViewFactoryCreator());
|
||||
}
|
||||
}
|
||||
|
||||
private void parseExpressionParser(Element element, BeanDefinitionBuilder definitionBuilder) {
|
||||
String expressionParser = element.getAttribute(EXPRESSION_PARSER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(expressionParser)) {
|
||||
definitionBuilder.addPropertyReference(EXPRESSION_PARSER_PROPERTY, expressionParser);
|
||||
} else {
|
||||
definitionBuilder.addPropertyValue(EXPRESSION_PARSER_PROPERTY, new WebFlowELExpressionParser());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<xsd:schema
|
||||
xmlns="http://www.springframework.org/schema/faces-config"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
targetNamespace="http://www.springframework.org/schema/faces-config"
|
||||
elementFormDefault="qualified" attributeFormDefault="unqualified"
|
||||
version="2.0">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" />
|
||||
|
||||
<xsd:element name="flow-builder-services">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
Deploys the flow builder services, including the ViewFactoryCreator, ExpressionParser, and ConversionService to
|
||||
be used by a flow definition registry.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attribute name="enable-managed-beans" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
When this attribute is set to true, a special EL expression parser will be enabled that allows access to JSF-managed beans
|
||||
from EL expressions in flow definitions.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="expression-parser" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
The idref of the expression parser instance that should be used. If not provided, the default OGNL expression parser
|
||||
will be used.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="view-factory-creator" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
The idref of the view factory creator that should be used. The view factory creator is specific to the view technology
|
||||
being used. If not provided, the default Spring MVC view factory creator will be used.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="conversion-service" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
The idref of the conversion service that should be used. If not provided, the default conversion service will be used.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
<!--
|
||||
<xsd:attribute name="enable-managed-beans" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
When this attribute is set to true, a special EL expression parser will be enabled that allows access to JSF-managed beans
|
||||
from EL expressions in flow definitions.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
-->
|
||||
</xsd:schema>
|
||||
@@ -31,6 +31,10 @@ public class LegacyJSFELExpressionParser extends ELExpressionParser {
|
||||
putContextFactory(MutableAttributeMap.class, new AttributeMapELContextFactory());
|
||||
}
|
||||
|
||||
public LegacyJSFELExpressionParser() {
|
||||
this(ExpressionFactory.newInstance());
|
||||
}
|
||||
|
||||
private static class RequestContextELContextFactory implements ELContextFactory {
|
||||
public ELContext getELContext(Object target) {
|
||||
List customResolvers = new ArrayList();
|
||||
|
||||
Reference in New Issue
Block a user