Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have working struts1 dispatch action and a form having two submit buttons which have parameter and value which calls method name with value. Well there is no problem.

But when clicking on delete button, I want to confirm with bootstrap dialog.
JavaScript
$('.btnDelete').on('click', function(e){
        var $form=$(this).closest('form');
        e.preventDefault();
        $('#confirm').modal({ backdrop: 'static', keyboard: false })
        .one('click', '#delete', function (e) {
            var sectorId = $(this).parent().parent().children()[0].innerHTML;
            var input = document.createElement("input");
            input.setAttribute("type", "hidden");
            input.setAttribute("name", "sectorId");
            input.setAttribute("value", sectorId);
            document.getElementById("sectorForm").appendChild(input);
            $("#sectorForm").submit();
        });
    });

Here e.preventDefault() is needed to stop form submitting. And when a delete button is clicked from dialog a hidden parameter will be passed and form will submit. But sever shows below error message.

HTTP Status 500 - Request[/SectorManagement] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.

Please note that there is no problem when removing bootstrap dialog.

I would appreciate any help,
Thank you.

What I have tried:

As you can see, I am trying to confirm delete action using bootstrap dialog.
The problem is that why default submission and jquery submission is different.
i.e. Submitting using jquery does not passing parameters to dispatch action.
Posted
Updated 27-Feb-16 0:04am

1 solution

The solution was to add one more add hidden parameter named action and value.
JavaScript
$('.btnDelete').on('click', function(e){
    var $form=$(this).closest('form');
    e.preventDefault();
    $('#confirm').modal({ backdrop: 'static', keyboard: false })
    .one('click', '#delete', function (e) {
        var sectorId = $(this).parent().parent().children()[0].innerHTML;
        var input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "sectorId");
        input.setAttribute("value", sectorId);
        document.getElementById("sectorForm").appendChild(input);
        input = document.createElement("input");
        input.setAttribute("type", "hidden");
        input.setAttribute("name", "action");
        input.setAttribute("value", delete);
        document.getElementById("sectorForm").appendChild(input);
        $("#sectorForm").submit();
    });
});

I don't know but there can be better solution. Will wait for your answers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900