flow EL resolver
This commit is contained in:
@@ -20,6 +20,7 @@ import javax.faces.el.PropertyResolver;
|
||||
|
||||
import org.springframework.binding.expression.el.MapAdaptableELResolver;
|
||||
import org.springframework.faces.expression.ELDelegatingPropertyResolver;
|
||||
import org.springframework.webflow.expression.el.FlowResourceELResolver;
|
||||
|
||||
/**
|
||||
* For resolving MapAdaptable properties with JSF 1.1 or >.
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
public class FlowResourceELResolver extends ELResolver {
|
||||
|
||||
private String MESSAGE_SOURCE_KEY = "resourceBundle";
|
||||
|
||||
public Class getCommonPropertyType(ELContext context, Object base) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
public Iterator getFeatureDescriptors(ELContext context, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) {
|
||||
if (base == null && MESSAGE_SOURCE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return MessageSource.class;
|
||||
} else if (base != null && base instanceof MessageSource) {
|
||||
MessageSource messageSource = (MessageSource) base;
|
||||
String message = messageSource.getMessage(property.toString(), null, RequestContextHolder
|
||||
.getRequestContext().getExternalContext().getLocale());
|
||||
if (StringUtils.hasText(message)) {
|
||||
context.setPropertyResolved(true);
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context, Object base, Object property) {
|
||||
if (base == null && MESSAGE_SOURCE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return RequestContextHolder.getRequestContext().getActiveFlow().getApplicationContext();
|
||||
} else if (base != null && base instanceof MessageSource) {
|
||||
MessageSource messageSource = (MessageSource) base;
|
||||
String message = messageSource.getMessage(property.toString(), null, RequestContextHolder
|
||||
.getRequestContext().getExternalContext().getLocale());
|
||||
if (StringUtils.hasText(message)) {
|
||||
context.setPropertyResolved(true);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext context, Object base, Object property) {
|
||||
if (base == null && MESSAGE_SOURCE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setValue(ELContext context, Object base, Object property, Object value) {
|
||||
if (base == null && MESSAGE_SOURCE_KEY.equals(property)) {
|
||||
throw new PropertyNotWritableException("The flow's MessageSource is not writable.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import javax.el.CompositeELResolver;
|
||||
import javax.faces.el.VariableResolver;
|
||||
|
||||
import org.springframework.faces.expression.ELDelegatingVariableResolver;
|
||||
import org.springframework.webflow.expression.el.FlowResourceELResolver;
|
||||
import org.springframework.webflow.expression.el.ImplicitFlowVariableELResolver;
|
||||
import org.springframework.webflow.expression.el.RequestContextELResolver;
|
||||
import org.springframework.webflow.expression.el.ScopeSearchingELResolver;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.binding.expression.el.ELContextFactory;
|
||||
import org.springframework.binding.expression.el.ELExpressionParser;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.expression.el.ActionMethodELResolver;
|
||||
import org.springframework.webflow.expression.el.FlowResourceELResolver;
|
||||
import org.springframework.webflow.expression.el.ImplicitFlowVariableELResolver;
|
||||
import org.springframework.webflow.expression.el.RequestContextELResolver;
|
||||
import org.springframework.webflow.expression.el.ScopeSearchingELResolver;
|
||||
@@ -52,6 +53,7 @@ public class JsfManagedBeanAwareELExpressionParser extends ELExpressionParser {
|
||||
RequestContext context = (RequestContext) target;
|
||||
List customResolvers = new ArrayList();
|
||||
customResolvers.add(new RequestContextELResolver(context));
|
||||
customResolvers.add(new FlowResourceELResolver(context));
|
||||
customResolvers.add(new ImplicitFlowVariableELResolver(context));
|
||||
customResolvers.add(new ScopeSearchingELResolver(context));
|
||||
customResolvers.add(new SpringBeanWebFlowELResolver(context));
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.springframework.webflow.expression.el;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.webflow.execution.RequestContext;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
/**
|
||||
* Custom EL resolver that resolves the messages from the active flow's {@link MessageSource}. The message source is
|
||||
* indexed under the key <code>resourceBundle</code>. To access a message, specify its key e.g.
|
||||
* <code>resourceBundle.myMessage</code>.
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class FlowResourceELResolver extends ELResolver {
|
||||
|
||||
private String RESOURCE_BUNDLE_KEY = "resourceBundle";
|
||||
|
||||
private RequestContext requestContext;
|
||||
|
||||
public FlowResourceELResolver() {
|
||||
}
|
||||
|
||||
public FlowResourceELResolver(RequestContext requestContext) {
|
||||
this.requestContext = requestContext;
|
||||
}
|
||||
|
||||
public Class getCommonPropertyType(ELContext context, Object base) {
|
||||
if (base == null) {
|
||||
return MessageSource.class;
|
||||
} else if (base instanceof MessageSource) {
|
||||
return String.class;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator getFeatureDescriptors(ELContext context, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getType(ELContext context, Object base, Object property) {
|
||||
if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return MessageSource.class;
|
||||
} else if (base instanceof MessageSource) {
|
||||
MessageSource messageSource = (MessageSource) base;
|
||||
String message = messageSource.getMessage(property.toString(), null, null, getLocale());
|
||||
if (message != null) {
|
||||
context.setPropertyResolved(true);
|
||||
return String.class;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context, Object base, Object property) {
|
||||
if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return getMessageSource();
|
||||
} else if (base instanceof MessageSource) {
|
||||
MessageSource messageSource = (MessageSource) base;
|
||||
String message = messageSource.getMessage(property.toString(), null, null, getLocale());
|
||||
if (message != null) {
|
||||
context.setPropertyResolved(true);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext context, Object base, Object property) {
|
||||
if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
|
||||
context.setPropertyResolved(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setValue(ELContext context, Object base, Object property, Object value) {
|
||||
if (base == null && RESOURCE_BUNDLE_KEY.equals(property)) {
|
||||
throw new PropertyNotWritableException("The flow's MessageSource is not writable.");
|
||||
}
|
||||
}
|
||||
|
||||
protected Locale getLocale() {
|
||||
return getRequestContext().getExternalContext().getLocale();
|
||||
}
|
||||
|
||||
protected MessageSource getMessageSource() {
|
||||
return getRequestContext().getActiveFlow().getApplicationContext();
|
||||
}
|
||||
|
||||
protected RequestContext getRequestContext() {
|
||||
return requestContext != null ? requestContext : RequestContextHolder.getRequestContext();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,6 +54,7 @@ public class WebFlowELExpressionParser extends ELExpressionParser {
|
||||
RequestContext context = (RequestContext) target;
|
||||
List customResolvers = new ArrayList();
|
||||
customResolvers.add(new RequestContextELResolver(context));
|
||||
customResolvers.add(new FlowResourceELResolver(context));
|
||||
customResolvers.add(new ImplicitFlowVariableELResolver(context));
|
||||
customResolvers.add(new ScopeSearchingELResolver(context));
|
||||
customResolvers.add(new SpringBeanWebFlowELResolver(context));
|
||||
|
||||
Reference in New Issue
Block a user