Edit and Delete button in each row connecting with SpringMVC

Edit and Delete button in each row connecting with SpringMVC

TGoncalvesTGoncalves Posts: 2Questions: 1Answers: 0

I`m trying to put two buttons for each row Delete and Edit in sequence add a function to this buttons, maybe using a link href or another way, to mapping on a Java controller using RequestMapping

Before post I destroy my table and build again because the form and table is on the same JSP page, thats a functional requirement

var myTable;

        initTable();
function initTable() {
            myTable = $('#datatable-responsive').DataTable({
                "ajax" : {
                    url : "jquery",
                    dataType : 'json',

                    success : function(data) {
                        $.each(data, function(index, value) {
                            myTable.row.add(value);
                        });
                        myTable.draw();
                    }

                },
                "paging" : true,
                "lengthChange" : true,
                "searching" : true,
                "ordering" : true,
                "info" : true,
                "autoWidth" : true,
                "data" : [],
                "columns" : [ {
                    "title" : "Name",
                    "data" : "name"
                }, {
                    "title" : "LastName",
                    "data" : "lastname"
                }, {
                    "title" : "Address",
                    "data" : "address"
                }, {
                    "title" : "City",
                    "data" : "city"
                } ]
            });

This is how I post using JS and Mapping in Java controller

$("#submit-form").submit(function(event) {
            // Prevent the form from submitting via the browser.
            event.preventDefault();
            ajaxPost();

        });

        function ajaxPost() {

            // PREPARE FORM DATA
            var formData = {
                Name: $("#name").val(),
                LastName: $("#lastname").val(),
                Address: $("#address").val(),
                City: $("#city").val(),

            }

            // DO POST
            $.ajax({
                headers : {
                    'Accept' : 'application/json',
                    'Content-Type' : 'application/json'
                },

                type : "POST",
                contentType : "/add-customer",
                url : url + "/submit-form",
                data : JSON.stringify(formData),
                dataType : 'json'

            });

            // Reset FormData after Posting
            resetData();
            myTable.clear();
            myTable.destroy();
            delay();  <<-- Only to make sure the insertion is done before the select
            initTable();
        }

        function resetData() {
            $("#name").val("");
            $("#lastname").val("");
            $("#address").val("");
            $("#city").val("");
        }

JAVA Controller

    @RequestMapping(value = "/add-customer/submit-form", method = RequestMethod.POST)
    public String save(@RequestBody Custumer customer) {

        custumerRepository.save(customer);

        return "/app/add-customer";

    }

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    I'm not actually sure what your question is I'm afraid. Could you state it explicitly?

    Are you asking how to connect a button to your Spring backend? I'm afraid you would need to ask in a Spring forum about that.

    Allan

  • TGoncalvesTGoncalves Posts: 2Questions: 1Answers: 0

    I realized my mistake.. sorry about that..
    My question its about insert a button inside in a table row with a url link for ajax request.

    I already fix it! Thanks!

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Just to confirm, are you saying that the question is resolved?

This discussion has been closed.