spring-projects / spring-webflow

Spring Web Flow
https://spring.io/projects/spring-webflow
Apache License 2.0
331 stars 234 forks source link

Issues binding to array of custom editor [SWF-1495] #683

Open spring-operator opened 13 years ago

spring-operator commented 13 years ago

Peter Tang opened SWF-1495 and commented

The Binding model cannot find proper converting property editor when binding to an array of custom type.

The 'findSpringConvertingPropertyEditor' method of BindingModel finds a TypeDescriptor of types.CustomType[] when perhaps it should be types.CustomType?

this occurs when trying to bind multiple checkboxes to an array property.

ex. Model:

public class Model {
   private MyType[] options = {MyType.TYPE_1, MyType.TYPE_2};
   private MyType[] selected;

   // getter & setters
}

View - jsp file

....
<c:forEach items="${model.options}" var="option">
   <form:checkbox path="selected" value="${option}" id="selected${option}" /> <label for="selected${option}"><spring:message message="${option}" /></label>
</c:forEach>

Notes: The value option prints out the toString() method of the MyType class (because it cannot find the proper converter) The same model/jsp and converters bind properly when using the Spring MVC binder. The converter works because using a hidden input tag will bind properly if oneSelected is a field of type MyType.


Affects: 2.3.0

4 votes, 4 watchers

spring-operator commented 13 years ago

Peter Tang commented

When trying to convert, the assert line of GenericConversionService below fails:

Assert.isTrue(source == null || sourceType.getObjectType().isInstance(source));

spring-operator commented 13 years ago

Peter Tang commented

I should have created this ticket with a higher priority. Is there a way to change it. When do you think you can take a look at it, confirm it is an issue?

Thanks, Peter.

spring-operator commented 12 years ago

Rossen Stoyanchev commented

Would you be able to reproduce the issue at the Spring Web Flow issue github repo? There are instructions and template projects to make it as easy as possible.

spring-operator commented 12 years ago

Peter Tang commented

Sure I'll give it a try.

spring-operator commented 12 years ago

Rossen Stoyanchev commented

I've started a project at the issue repository. It contains the code mentioned but does not yet reproduce the issue. Can you take a look and add what's missing? You can fork the repository, modify the project, and send a pull request. If you can help demonstrate the issue we can consider it for 3.1.1 or otherwise it'll have to be postponed.

spring-operator commented 12 years ago

Peter Tang commented

It's because MyType is supposed to be a class with a custom converter. Will try and update with an example but not sure I will get to it before 3.1.1 also.

Thanks.

spring-operator commented 12 years ago

Rossen Stoyanchev commented

That would be great, thanks. You meant before 2.3.1 I think.

spring-operator commented 12 years ago

Rossen Stoyanchev commented

Postponing to allow more time to reproduce the issue.

spring-operator commented 11 years ago

Sebastian Stenzel commented

Issue still exists with spring-webflow 2.3.1 for any type of Collection. The problem lies in the following code section (org.springframework.webflow.mvc.view.BindingModel:274):

if (valueType != null) {
    BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(boundObject);
    TypeDescriptor typeDescriptor = accessor.getPropertyTypeDescriptor(field);
    return new ConvertingPropertyEditorAdapter(conversionService, converterId, typeDescriptor);
}

Even though the correct type ("valueType") is supplied, it is not used to create the ConvertingPropertyEditorAdapter.