0

On ItemController :

@RequestMapping(value="/delete.htm", produces="application/json", method=RequestMethod.POST)
public @ResponseBody Item deleteItem(
            @RequestParam String itemName) {

    Item existingItem = new Item();
    existingItem.setItemName(itemName);
    itemService.deleteItem(existingItem);
    return existingItem;
}

On ItemDao Impl:

@Override
public void deleteItem(Item item) {
    // TODO Auto-generated method stub
    sessionFactory.getCurrentSession().delete(item);
}

on Item ServiceImpl:

@Transactional
public void deleteItem(Item item) {
    // TODO Auto-generated method stub
    itemDao.deleteItem(item);
}

On Jquery Grid i am using delete function:

function deleteRow(obj, args) { 
    // Get the currently selected row 
    var row = $('#grid').jqGrid('getGridParam','selrow');

    // A pop-up dialog will appear to confirm the selected action
    if (row != null) { 
        $('#grid').jqGrid('delGridRow', row, {
            url: 'delete.htm',
            recreateForm: true,
            beforeShowForm: function (form) {
                //Change title
                $(".delmsg").replaceWith('<span style="white-space: pre;">' +
                                     'Delete selected record?' + '</span>');
                //hide arrows
                $('#pData').hide();
                $('#nData').hide();
            },
            reloadAfterSubmit: true,
            closeAfterDelete: true,
            serializeDelData: function (postdata) {
                var rowdata = $('#grid').getRowData(postdata.id);
                // append postdata with any information 
                return {
                    id: postdata.id,
                    oper: postdata.oper,
                    username: rowdata.username
                };
            },
            afterSubmit: function (response, postdata) {
                var result = eval('(' + response.responseText + ')');
                var errors = "";

                if (result.success == false) {
                    for (var i = 0; i < result.message.length; i++) {
                        errors += result.message[i] + "<br/>";
                    }
                } else {
                    $('#msgbox').text('Entry has been deleted successfully');
                    $('#msgbox').dialog({
                        title: 'Success',
                        modal: true,
                        buttons: {
                            "Ok": function () {
                                $(this).dialog("close");
                            }
                        }
                    });
                }
                // only used for adding new records
                var newId = null;

                return [result.success, errors, newId];
            }
        });
    } else {
        $('#msgbox').text('You must select a record first!');
        $('#msgbox').dialog({
            title: 'Error',
            modal: true,
            buttons: {
                "Ok": function () {
                    $(this).dialog("close");
                }
            }
        });
    }
}

I am getting below error:error Status: 'Bad Request'. Error code: 400 Delete selected record? where i am getting error at controller or in jq grid? kindly suggest

azz
  • 5,852
  • 3
  • 30
  • 58

2 Answers2

0

That means you are not correctly mapping your controller from your ajax jquery call(?).

I am not familiar with jqGrid but check you are doing a post and that the request parameter is defined correctly.

(The logic and naming convention you use are a mite confusing btw.)

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
-1

HTTP-Response Code 400 states, that there is something wrong with your request. Just check if the call to your webservice is correct (path, parameters etc.).

Furthermore you could take a look at your server log files to get an explanation what you are doing wrong on the client side. Spring-mvc maps the Response Code 400 to a number of Exceptions (have a look here). By analyzing the exception you could understand what's wrong with your request.

benjiman
  • 3,888
  • 4
  • 29
  • 44
  • its nothign to do witht he service, that woul dbe a 500 error. – NimChimpsky Apr 16 '13 at 12:13
  • I didn't mean that the error itsself is at the server side. I know that Bad Request is fault of the client. What I wanted to say is that the error is given back by the server and that by analyzing his log files he may find out what he is doing wrong on the client side (i.e. if he is trying to delete an entity that doesn't exist). – benjiman Apr 16 '13 at 12:21
  • if he tries to delete an entity that doesn;t exist he won't get a 400 error. – NimChimpsky Apr 16 '13 at 12:24
  • depending on the exception handling/mapping he might get an 404 - correct. But my point is that it could be helpful to take a look at the exception that causes the http repsonse to get a better understanding of what he is actually doing wrong on the client side. – benjiman Apr 16 '13 at 12:28
  • "depending on the exception handling/mapping he might get an 404 - correct." No, unless they have delibreatley caught an exception and handled it by throwing a completing inappropriate/unrelated exception. – NimChimpsky Apr 16 '13 at 12:42
  • Doesn't matter what 4xx repsonse code he is getting. I don't see no reason why the exception that caused it couldn't be helpful to understand what's wrong with the client request. – benjiman Apr 16 '13 at 12:52
  • If you agree 100% why the down vote :) btw it's quite common to use 404 as a repsonse for a delete action where the entity is not found and I don't see what's wrong with that, after all the action is a dead link if the entity has gone. – benjiman Apr 16 '13 at 13:05
  • 404 for a reponse of delete where not found, that might be ok http://stackoverflow.com/a/6440279/106261 as would 200. But its not pertinent to the OP. – NimChimpsky Apr 16 '13 at 13:13