views:

539

answers:

1

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.

  1. A Web Form is simulating a User. User can have name and List of phoneNumbers.

  2. phoneNumbers can be added dynamically using Javascript at client side.

  3. Dynamic addition of phoneNumber into phoneNumbers is not a problem - Thanks to LazyList / AutoPopulatingList.

  4. 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?

A: 

Hi,

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,

Arthur Ronald F D Garcia
I used the same AJAX approach in one project. Sent an ajax delete request and if it was successfull I removed the row via DOM calls.
NA