java - Spring MVC - Instantiate nested object only when input is filled -
i have these models:
@entity public class user { //... @notblank private string login; @notblank private string password; @valid @onetoone private person person; //... } // , @entity public class person { //... @notblank private string name; //... }
and insert method in user controller:
@requestmapping(method = post) public string insert(@valid user user, bindingresult result){ }
and form
<p>login : <input type="text" name="login" /></p> <p>pass : <input type="text" name="password" /></p> <p>name : <input type="text" name="person.name" /></p>
association between person , user optional. don't need fill person.name
input.
but when controller receive user's information @valid
annotation validating both user , person objects person.name
empty.
i realized controller receiving person object instance always.
is possible receive null in person when person.name
input not filled?
when remove person.name
input form, ok, receive null. peson name optional , cant remove form.
try remove @notblank @ person name :
@entity public class person { private string name; }
Comments
Post a Comment