Frage

I have a modal form (using bootstrap) that I use to add a user. This form is wired to a 'addUser' method via RequestMapping in my Controller. Adding a user works fine.

Is there a simple way I can populate the same modal form to edit existing user details after clicking an edit button? Do I have to make an AJAX call to a REST endpoint to populate the form, or is there a better way of doing this?

I'm using Spring Boot.

Thanks, Jerry

War es hilfreich?

Lösung

An AJAX request would be your best bet, otherwise you'd have to load all the editable user properties ahead of time when you load the page of existing users and store them in memory or on the page somehow. It's not the most efficient solution though because you're loading all those properties for all users, every time you reload the page. If you only have a handful of users, that might be ok for you, but if you're dealing with a large set of users, then that will make for longer request times.

Andere Tipps

Yes you can make a ajax request and get the modal details in form of Json or Xml. Below example retrieve the user details and set it into modal form variables like userName

$.ajax({
        type: "post",
        url: "Url to get the response",
        cache: false,               
        data:'userId=' + $("#userId").val(),
        success: function(response){
            var obj = JSON.parse(response);
            $('#userName').val(obj.userName);
        },
        error: function(){                      
            alert('Error while request..');
        }
    }); 
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top