aspose file tools*
The moose likes Spring and the fly likes Spring MVC. SimpleFormController with AutoPopulatingList. How to detect fewer items? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC. SimpleFormController with AutoPopulatingList. How to detect fewer items?" Watch "Spring MVC. SimpleFormController with AutoPopulatingList. How to detect fewer items?" New topic
Author

Spring MVC. SimpleFormController with AutoPopulatingList. How to detect fewer items?

Edward Winchester
Ranch Hand

Joined: Sep 16, 2009
Posts: 65
Hello,

I have a domain object which aggregates other objects. e.g: a person can have many email addresses. So there's a Person class with a List<EMail> emails member.

I want a web form to edit the person object. I'll have some Javascript to add/delete the email addresses. After some investigation I found AutoPopulatingList which will grow if more email addresses have been specified on the form.

My question is what happens if email addresses are deleted? I've knocked up a small test program and it appears that the list doesn't shrink. I was wondering how this is supposed to work?

Thanks,

Ed
arunpillai kkk
Greenhorn

Joined: Sep 23, 2009
Posts: 2
Hii..Autopopulating list, is it populated when the email address is added,
if you have any control over that list, then you can easily delete the value in autopopulating list when
user deletes the email id.



outsource Web Development, Outsource Web Developers, outsource website Development India, Outsource CMS Developers outsource Web Design, Outsource Web Designer, Outsource Web Designer India, Outsource CMS Developers
Edward Winchester
Ranch Hand

Joined: Sep 16, 2009
Posts: 65
I'm overriding onSubmit that accepts an java.lang.Object. At this stage Spring has bound the form fields to the object. I can further manipulate the list of emails but I don't have information at this stage about what's been deleted on the form.

Will I need to override a different onSubmit and interrogate the request myself then?
Edward Winchester
Ranch Hand

Joined: Sep 16, 2009
Posts: 65
arunpillai kkk wrote: Hii..Autopopulating list, is it populated when the email address is added,
if you have any control over that list, then you can easily delete the value in autopopulating list when
user deletes the email id.



Some code or hints to where I can put this logic would be beneficial.
Edward Winchester
Ranch Hand

Joined: Sep 16, 2009
Posts: 65
Inviting more participants in this thread please!

I've been investigating formBackingObject() a bit more and didn't realise it gets called when the form is being presented and when the form is being submitted. Therefore, I think the following logic is what I need and hopefully someone might confirm I'm using this part of Spring as intended:

If formBackingObject() is being called because the form is about to be shown, then the application should create a new object perhaps initialising it with information from a database.

If formBackingObject() is being called because the form is being submitted, then an object should be created but there's no need to initialise it as that data is about to be overwritten from the form. In fact, if the object contains a list of child items, then it'd be dangerous to initialise it because any that are deleted by the user on the HTML form will not be deleted from the list.

Thanks,

Ed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC. SimpleFormController with AutoPopulatingList. How to detect fewer items?