Confused with spring MVC JSP page binding?

Up vote 0 down vote favorite share g+ share fb share tw.

I have not been able to solve my binding problem. I have one class Person Class Person { Private fname; private lname; public Address address; Now one other class class Address { private street; private suburb; } in controller I have model. AddAttribute("personAttribute", new Person()); IN jsp page I have Uptill this evrrythng is ok but when I add Then becomes the problem .

I don't know how can I add Adress object with person. I mean do I have to do model. AddAttribute("personAttribute", new Person(new Address())); or model.

AddAttribute("addressAttribute", new Address()); or td> java jsp data-binding spring-mvc link|improve this question asked Mar 6 '11 at 10:59John.

You have to bind path like that : It's because you are in scope of Person object in binding.

I have Set in person object will that make any difference – John Mar 6 '11 at 12:04 @Pasha Yes it makes. I recommend to you AutoPopulatingList in this case. Then you have to bind address like addresses1, addresses2 ... – krocan Mar 6 '11 at 12:21 actually I am not retrieving , but I am inserting values.

So like your address. Street (it worked) , how can now I write like Address. Street or what.

Is there any online example where list or set is binded in spring form – John Mar 6 '11 at 13:11 Read/write is managed by binding, so if you bind correctly your data object correctly, that when you POST it to server you have it filled in your method in input argument annotated with @ModelAttribute. Refer to Spring doc – krocan Mar 6 '11 at 13:13.

The following code is correct: model. AddAttribute("personAttribute", new Person()); This will initialize the Person with empty attributes, including an empty Address. If you want to make sure that the address is not empty, you have to pass a person instance that contains a value.

For example Person person = new Person(); person. SetFirstName("John"); person. SetLastName("Smith"); Address address = new Address(); address.

SetStreet("#10 Avenue"); address. SetSuburb("Cook"); person. SetAddress(address); Normally you may want to populate the person object with a value retrieved from a database or data source.

Actually I am inserting value in database . So can you please explain what I have to write in jsp page like person.address. Street is valid name there – John Mar 6 '11 at 11:49.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions