SWF-611- Provide easy access to a flow's local MessageSource through EL in JSF templates.

This commit is contained in:
Jeremy Grelle
2008-04-15 22:04:39 +00:00
parent 355757d3d8
commit 12486677c0
4 changed files with 75 additions and 1 deletions

View File

@@ -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.");
}
}
}

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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>