etschreiber
Jan 28th, 2005, 02:46 PM
The following is from the javadoc for org.springframework.validation.DataBinder
public void registerCustomEditor(Class requiredType,
String field,
PropertyEditor propertyEditor)
...If the field denotes an array or Collection, the PropertyEditor will get applied either to the array/Collection itself (the PropertyEditor has to create an array or Collection value) or to each element (the PropertyEditor has to create the element type), depending on the specified required type.
Lets say I have a set of Person objects inside of a Company object:
public class Person {
private long personId;
private String firstName;
private String lastName;
// Getters and setters here.
}
public class Company {
private Set people; // Set of people objects.
// Getters and setters here.
}
Based on the aforementioned javadoc, I would think I would have two choices for the initBinder method:
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
{
binder.registerCustomEditor(Set.class, "people", new PersonEditor());
}
OR
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
{
binder.registerCustomEditor(Person.class, "people", new PersonEditor());
}
I would expect the first custom editor to be called once for the whole people set and the second custom editor to be called once for each person in the people set. In practice, I can only get the custom edittor registed with Set.class as its required type. Is there a way to register the custom editor to be called for each member of the set? That seems to be the implication from the javadoc. Perhaps I am misreading?
Thank you for your time.
Sincerely,
Ethan Schreiber
public void registerCustomEditor(Class requiredType,
String field,
PropertyEditor propertyEditor)
...If the field denotes an array or Collection, the PropertyEditor will get applied either to the array/Collection itself (the PropertyEditor has to create an array or Collection value) or to each element (the PropertyEditor has to create the element type), depending on the specified required type.
Lets say I have a set of Person objects inside of a Company object:
public class Person {
private long personId;
private String firstName;
private String lastName;
// Getters and setters here.
}
public class Company {
private Set people; // Set of people objects.
// Getters and setters here.
}
Based on the aforementioned javadoc, I would think I would have two choices for the initBinder method:
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
{
binder.registerCustomEditor(Set.class, "people", new PersonEditor());
}
OR
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
{
binder.registerCustomEditor(Person.class, "people", new PersonEditor());
}
I would expect the first custom editor to be called once for the whole people set and the second custom editor to be called once for each person in the people set. In practice, I can only get the custom edittor registed with Set.class as its required type. Is there a way to register the custom editor to be called for each member of the set? That seems to be the implication from the javadoc. Perhaps I am misreading?
Thank you for your time.
Sincerely,
Ethan Schreiber