SWF-611- Provide easy access to a flow's local MessageSource through EL in JSF templates.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package org.springframework.faces.webflow;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.webflow.execution.RequestContextHolder;
|
||||
|
||||
public class FlowMessageSourceResolver 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, FacesContext.getCurrentInstance()
|
||||
.getViewRoot().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, FacesContext.getCurrentInstance()
|
||||
.getViewRoot().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.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class FlowPropertyResolver extends ELDelegatingPropertyResolver {
|
||||
private static final CompositeELResolver composite = new CompositeELResolver();
|
||||
|
||||
static {
|
||||
composite.add(new FlowMessageSourceResolver());
|
||||
composite.add(new MapAdaptableELResolver());
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public class FlowVariableResolver extends ELDelegatingVariableResolver {
|
||||
static {
|
||||
composite.add(new RequestContextELResolver());
|
||||
composite.add(new ImplicitFlowVariableELResolver());
|
||||
composite.add(new FlowMessageSourceResolver());
|
||||
composite.add(new ScopeSearchingELResolver());
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<action-listener>org.springframework.faces.webflow.FlowActionListener</action-listener>
|
||||
<action-listener>org.springframework.faces.model.SelectionTrackingActionListener</action-listener>
|
||||
<variable-resolver>org.springframework.faces.webflow.FlowVariableResolver</variable-resolver>
|
||||
<property-resolver>org.springframework.faces.webflow.FlowPropertyResolver</property-resolver>
|
||||
<variable-resolver>org.springframework.faces.webflow.SpringBeanWebFlowVariableResolver</variable-resolver>
|
||||
<property-resolver>org.springframework.faces.webflow.FlowPropertyResolver</property-resolver>
|
||||
<view-handler>org.springframework.faces.webflow.FlowViewHandler</view-handler>
|
||||
</application>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user