Müsli
Müsli

Reputation: 1774

spring mvc list<Long> as parameter in controller method

I need same help with same issue i have. I need to pass a list of long object as parameters in a controller method, that is call via jquery.

here is the code

@RequestMapping(value="/path/retrieve")
    public @ResponseBody String retrieve(@RequestParam List<Long> ids) {
        *******
    }

and the jquery call

var aids = new Array();
aids.push(busId);
ajaxCall('path/retrieve.html', {
                ids : aids
            }, function() { // more code **********
});

the ajaxCall it is a function with this code:

function ajaxCall(url, data, callback, onError) {

    jQuery.ajax({
        type : 'POST',
        url : url,
        dataType : 'json',
        data : data,
        success : function(actionResult) {
            actionResult = eval(actionResult);
            // these kind of calls must return an action result.
            if (callback != undefined || callback != null)
                callback(actionResult); // invoke callback passing object result
        },
        error : function(jqXHR, textStatus, errorThrown) {
            if (onError != undefined && onError != null)
                onError(jqXHR, textStatus, errorThrown);
            else
                ajaxCallOnError(jqXHR, textStatus, errorThrown);
        }
    });
}

well, when i trying to make the call i get the following error

HTTP 400 - The request sent by the client was syntactically incorrect ()

i assume that the controller does not accept a List as parameter, how can i solved this problem?

Upvotes: 0

Views: 2397

Answers (2)

Yogendra Rampuria
Yogendra Rampuria

Reputation: 11

This might be coming from Controller (more precisely from Spring Binding). I am not aware for request parameter to List conversion. You can have String[] or List. When spring framework is unable to convert parameter to your desired datatype, it does give out Error 400.

Check @InitBinder annotation in spring documentation for writing your own converters.

I use it heavily for convertion date and time parameters. Specifically to auto convert all the time received to UTC

Upvotes: 1

Karthik Ramachandran
Karthik Ramachandran

Reputation: 12175

I don't think this is getting to the Controller. It looks like the web server is kicking back your request. I would use firebug or similar tool to take a look at the URL that ajaxCall generates and verify that it is correct.

Upvotes: 0

Related Questions