Reputation: 123
I have a typical scenario - I have read many articles on this and dynamic addition seems to work fine. I could not get elegant solution for dynamic delete.
A Web Form is simulating a User. User can have name and List of phoneNumbers.
phoneNumbers can be added dynamically using Javascript at client side.
Dynamic addition of phoneNumber into phoneNumbers is not a problem - Thanks to LazyList / AutoPopulatingList.
Dynamic Deletion is kind of an issue. Let's say the web form was rendered with phoneNumbers as {1,3,5,7,9}. Using Javascript the user removes {1,3} without submitting the form. Now when the form is submitted user.phoneNumbers should automatically have {5,7,9}.
Somehow, Spring MVC just doesn't contain the updated list. I am using annotation based controllers.
Gurus any help?
Upvotes: 3
Views: 2422
Reputation: 4030
I am seeing the same thing with Autopopulating list.
I use a dojo ajax call to 1) dojo.destroy the dom with the removed list value, then 2) on the server I do list.remove(index).
The value in the list ends up being null but the index and the size of the list remain the same size (the largest size possible ie: if 4 ajax add calls the list will remain a size of 4 even if one or several remove calls are completed).
Were you able to figure out why this was happening?
Upvotes: 0
Reputation: 33775
I usually do as follows
For each removed PhoneNumber object, i do a Ajax request. A PhoneNumberRepository takes care of deleting the PhoneNumber
@Repository
public class PhoneNumberRepositoryImpl implements PhoneNumberRepository {
public void removePhoneNumber(PhoneNumber phoneNumber) {
// code goes here
}
}
This way, you user will contain only PhoneNumber that has not been removed.
Here you can see how i remove / add collection based property. It works fine!
regards,
Upvotes: 1