Hi.
I am wondering is there way to bind objects with complex constructor.
If i have som object e.g
So if i send form data and then use in my controller annotation @ModelAttributeCode:public class MyObject1 { private Long _id; private String _name; public void setName(String name) { _name = name; } public String getName(String name) { return _name; } // .... here goes remaining setters and getters methods. }
This situation works.Code:public ModelAndView myController(@ModelAttribute("myObject1") MyObject1 myObject1 { // ... here goes remaining controller code }
But if my object is like this
Now i don't have simple construcor. So i can't create object like this :Code:public class MyObject2 { private final String _property; public MyObject2(String property) { _property = property; } private Long _id; private String _name; public void setName(String name) { _name = name; } public String getName(String name) { return _name; } // .... here goes remaining setters and getters methods. }
i have to use :Code:MyObject2 xxx= new MyObject2();
So when i'm binding form data to this new object i'm getting these exception:Code:MyObject2 yyy= new MyObject2("some property");
is there way to resolve this?Code:org.springframework.beans.InvalidPropertyException: Invalid property .... Could not instantiate property type [com.myPackage.MyObject2] to auto-grow nested property path: java.lang.InstantiationException
thanks.


Reply With Quote
