Let be my custom type (note that there is NO setters because this is an Immutable Value Object):
class CustomType extends ValueObject {
private String value;
@NotNull
public String getValue();
CustomType(String value) { this.value = value;}
CustomType(String prefix, String suffix) { this.value = prefix + suffix;}
public String getPrefix() { return value.substring(0, 4);}
public String getSuffix() { return value.substring(4);}
}
and my controller:
@Controller
class MyController {
public ModelAndView processSubmittedForm(@Valid CustomType myObject, BindingResult result) {..}
}
and my jsp view form:
<form>
<input id="prefixField" name="prefix" value="756." type="hidden">
<input id="suffixField" name="suffix" type="text">
...
<form/>
Considering that this view will send two POST parameters prefix
and suffix
, what do I need to do in order to have these two parameters be bound with the single object myObject
, assuming that it will be validated by Spring with a not-null value ?
Can I achieve this by customizing WebDataBinder, InitBinder, by registering a Formatter or by Custom Editor or whatever ?
Thank you very much for your help.
EDIT: Here are the related articles I have googled without finding one solution that matches my own issue :
- http://forum.springsource.org/showthread.php?130618-Custom-HandlerMethodArgumentResolver-that-uses-messageConverters
- Spring MVC customized method parameter binding
- Spring Partial Update Object Data Binding
- http://sergialmar.wordpress.com/2011/03/29/extending-handler-method-argument-resolution-in-spring-mvc/
- Custom WebArgumentResolver like @PathVariable