Romain Linsolas
Romain Linsolas

Reputation: 81647

Got a 404 error on my JavaScript route

I'm using Play! v2 and I added a JavaScript method on my page that tries to retrieve data from the server. The client sends 2 information, a deal and a boolean (withDebug).

My routes file:

GET     /:deal/tailLog              controllers.MyController.tailLog(deal: String, withDebug: Boolean)

I also tried that, without success:

GET     /:deal/tailLog?withDebug=:withDebug   controllers.MyController.tailLog(deal: String, withDebug: Boolean)

MyController class contains the following methods:

public static Result tailLog(String deal, Boolean withDebug) {
    ...
}

public static Result javascriptRoutes() {
    response().setContentType("text/javascript");
    return ok(Routes.javascriptRouter("jsRoutes",
            ...,
            controllers.routes.javascript.MyController.tailLog()
    ));
}

And finally, the JavaScript call is:

function tailLog() {
    var withDebug = $("#logs-debug").is(':checked');
    jsRoutes.controllers.MyController.tailLog('mydeal', withDebug).ajax({
        ...
    });
}

When this method is called, my application is calling the URL http://localhost:9000/mydeal/tailLog?withDebug=false, which is the URL pattern I want, but fails with a 404 error message.

Note that before I added the withDebug parameter, everything was working fine.

What am I doing wrong?

Thanks.

Upvotes: 1

Views: 133

Answers (1)

Julien Lafont
Julien Lafont

Reputation: 7877

In Play 2.0.4, you must use 0/1 to bind boolean parameters (and not false/true)

A little update in your javascript should fix this error:

var withDebug = $("#logs-debug").is(':checked') ? 1 : 0;

Upvotes: 2

Related Questions