Hello,
I ran into this situation this afternoon, I think I found a good
solution but I'm posting here to share it with you and find out if
there is an easier way to do that.
My application has a form with two addresses: Address and
BillingAddress. In my controller I'm instantiating a
ServletRequestDataBinder to bind my objects.
...
ServletRequestDataBinder binder = new ServletRequestDataBinder(t,key);
binder.bind(request);
...
The problem is that the binder will create the same object twice. Why?
because the spring:bind tag will fulfill the parameters attributes in
the form with the same name, not considering if it is an Address or a
BillingAddress.
To workaround the situation, I input the String billingAddress_
before each name. The problem now is that an ServletRequestDataBinder
is not useful anymore to bind my billingAddress. That generates much
more code but solves the problem:
final MutablePropertyValues mpvs = new MutablePropertyValues();
Closure c = new Closure()
{
public void execute(Object o)
{
Map.Entry<String, String> entry = (Map.Entry<String, String>)o;
if(entry.getKey().startsWith("billingAddress_"))
{
//billingAdress_.length=15
mpvs.addPropertyValue(entry.getKey().substring(15),
entry.getValue()); }
}
};
CollectionUtils.forAllDo(request.getParameterMap().entrySet(), c);
DataBinder binder = new DataBinder(billingAddress,"billingAddress");
binder.bind(mpvs);
I'm sure someone has ran into this problem before. Do you know a
better solution?
thanks,
Luiz
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]