custom converters
This commit is contained in:
@@ -260,8 +260,8 @@ public class ViewState extends TransitionableState {
|
||||
}
|
||||
|
||||
private void updateHistory(RequestControlContext context) {
|
||||
TransitionDefinition t = context.getCurrentTransition();
|
||||
History history = (History) t.getAttributes().get("history");
|
||||
TransitionDefinition transition = context.getCurrentTransition();
|
||||
History history = (History) transition.getAttributes().get("history");
|
||||
if (history == null || history == History.PRESERVE) {
|
||||
context.updateCurrentFlowExecutionSnapshot();
|
||||
} else if (history == History.DISCARD) {
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
*/
|
||||
package org.springframework.webflow.engine.builder.support;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionExecutorNotFoundException;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.binding.convert.service.GenericConversionService;
|
||||
import org.springframework.binding.expression.ExpressionParser;
|
||||
@@ -129,10 +132,15 @@ public class FlowBuilderContextImpl implements FlowBuilderContext {
|
||||
return getFlowBuilderServices().getConversionService().getConversionExecutor(sourceClass, targetClass);
|
||||
}
|
||||
|
||||
public ConversionExecutor[] getConversionExecutors(Class sourceClass) {
|
||||
public Set getConversionExecutors(Class sourceClass) {
|
||||
return getFlowBuilderServices().getConversionService().getConversionExecutors(sourceClass);
|
||||
}
|
||||
|
||||
public ConversionExecutor getConversionExecutor(String id, Class sourceClass, Class targetClass)
|
||||
throws ConversionExecutorNotFoundException {
|
||||
return getFlowBuilderServices().getConversionService().getConversionExecutor(id, sourceClass, targetClass);
|
||||
}
|
||||
|
||||
public Class getClassForAlias(String name) {
|
||||
return getFlowBuilderServices().getConversionService().getClassForAlias(name);
|
||||
}
|
||||
|
||||
@@ -23,18 +23,8 @@ import java.util.LinkedList;
|
||||
*/
|
||||
public class BinderModel extends AbstractModel {
|
||||
|
||||
private String autoBind;
|
||||
|
||||
private LinkedList bindings;
|
||||
|
||||
public String getAutoBind() {
|
||||
return autoBind;
|
||||
}
|
||||
|
||||
public void setAutoBind(String autoBind) {
|
||||
this.autoBind = autoBind;
|
||||
}
|
||||
|
||||
public LinkedList getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
@@ -49,7 +39,6 @@ public class BinderModel extends AbstractModel {
|
||||
|
||||
public void merge(Model model) {
|
||||
BinderModel binder = (BinderModel) model;
|
||||
setAutoBind(merge(getAutoBind(), binder.getAutoBind()));
|
||||
setBindings(merge(getBindings(), binder.getBindings()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,7 +523,6 @@ public class XmlFlowModelBuilder implements FlowModelBuilder {
|
||||
Element binderElement = DomUtils.getChildElementByTagName(element, "binder");
|
||||
if (binderElement != null) {
|
||||
BinderModel binder = new BinderModel();
|
||||
binder.setAutoBind(binderElement.getAttribute("auto-bind"));
|
||||
binder.setBindings(parseBindings(binderElement));
|
||||
return binder;
|
||||
} else {
|
||||
|
||||
@@ -377,18 +377,6 @@ A binding that is not required allows null and empty values to be bound.
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="auto-bind" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
Toggles automatic model binding. If true, binding between request parameters and model properties occurs automatically by convention.
|
||||
For example, the request parameter "firstName" might map to property "firstName" on a Person model.
|
||||
If false, binding must be explicitly enabled per property by configuring one or more binding elements.
|
||||
The default, if not overridden, is true.
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="on-entry" minOccurs="0">
|
||||
|
||||
@@ -261,12 +261,10 @@ public abstract class AbstractMvcView implements View {
|
||||
private boolean shouldBind(Object model) {
|
||||
TransitionableStateDefinition currentState = (TransitionableStateDefinition) requestContext.getCurrentState();
|
||||
TransitionDefinition transition = currentState.getTransition(eventId);
|
||||
if (transition != null) {
|
||||
if (transition.getAttributes().contains("bind")) {
|
||||
return transition.getAttributes().getBoolean("bind").booleanValue();
|
||||
}
|
||||
if (transition == null) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return transition.getAttributes().getBoolean("bind", Boolean.FALSE).booleanValue();
|
||||
}
|
||||
|
||||
private MappingResults bind(Object model) {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package org.springframework.webflow.config;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
import org.springframework.binding.convert.ConversionExecutionException;
|
||||
import org.springframework.binding.convert.ConversionExecutor;
|
||||
import org.springframework.binding.convert.ConversionExecutorNotFoundException;
|
||||
import org.springframework.binding.convert.ConversionService;
|
||||
import org.springframework.binding.convert.service.DefaultConversionService;
|
||||
import org.springframework.binding.expression.Expression;
|
||||
@@ -64,7 +67,12 @@ public class FlowBuilderServicesBeanDefinitionParserTests extends TestCase {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor[] getConversionExecutors(Class sourceClass) {
|
||||
public ConversionExecutor getConversionExecutor(String id, Class sourceClass, Class targetClass)
|
||||
throws ConversionExecutorNotFoundException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public Set getConversionExecutors(Class sourceClass) {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,6 @@ public class XmlFlowModelBuilderTests extends TestCase {
|
||||
FlowModel flow = builder.getFlowModel();
|
||||
ViewStateModel model = (ViewStateModel) flow.getStates().get(0);
|
||||
assertEquals("formObject", model.getModel());
|
||||
assertEquals("true", model.getBinder().getAutoBind());
|
||||
assertEquals("objectProperty", ((BindingModel) model.getBinder().getBindings().get(0)).getProperty());
|
||||
assertEquals("customConverter", ((BindingModel) model.getBinder().getBindings().get(0)).getConverter());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
|
||||
|
||||
<view-state id="form" model="formObject">
|
||||
<binder auto-bind="true">
|
||||
<binder>
|
||||
<binding property="objectProperty" converter="customConverter" required="true" />
|
||||
</binder>
|
||||
</view-state>
|
||||
|
||||
Reference in New Issue
Block a user