Spring Dynamic List Linking

I have a typical scenario - I read a lot of articles about this, and dynamic adding seems to work fine. I could not get an elegant solution for dynamic deletion.

  • The web form simulates a user. The user can have a name and a list of phone numbers.

  • phoneNumbers can be added dynamically using client-side Javascript.

  • Dynamically adding phoneNumber to phoneNumbers is not a problem - thanks to LazyList / AutoPopulatingList.

  • Dynamic deletion is a problem. Let's say the web form was made using phoneNumbers as {1,3,5,7,9}. Using Javascript, the user removes {1,3} without submitting the form. Now that the form is submitted, user.phoneNumbers should automatically have {5,7,9}.

Somehow, Spring MVC just does not contain an updated list. I use annotation based controllers.

Guru of any help?

+3
source share
2 answers

I usually do the following:

For each remote PhoneNumber object, I make an Ajax request . PhoneNumberRepository will take care of removing PhoneNumber

@Repository
public class PhoneNumberRepositoryImpl implements PhoneNumberRepository {

    public void removePhoneNumber(PhoneNumber phoneNumber) {
        // code goes here
    }

}

Thus, the user will only contain a phone number that has not been deleted.

Here you can see how to remove / add a property based on a collection. It works great!

Yours faithfully,

+1
source

I see the same with the autopopulation list.

ajax dojo 1) dojo.destroy dom , 2) list.remove(index).

, ( , ..: 4 ajax add calls, 4, ).

, ?

0

Source: https://habr.com/ru/post/1726989/


All Articles