• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Edward Winchester
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
a wee bit from the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic