Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PlayFramework 2.0.2 multiple parameters in routes

I cant seem to get multiple parameters to work if i add one parameter everything is fine as soon as i add a second parameter i always get a

No data received
Unable to load the webpage because the server sent no data.
Here are some suggestions:
Reload this webpage later.
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

Can anyone else confirm that you can add a second param to a request using play 2.0.2? (using java)

My url is as simple as this

http://localhost:9000/account/foruser?username=somethig&create=0

and the routes

GET     /account/foruser
controllers.user.UserController.foruser(username:String, create:Boolean ) 
like image 534
Anthony McCormick Avatar asked Aug 11 '12 01:08

Anthony McCormick


2 Answers

You should put some more attention on the routes docs and samples

In general if you're using named params with &name=value you don't need to specify them in the routes files. Instead use DynamicForm in the Java to access them.

Route file is used for matching unnamed parts of the link with controler's action and params. So your link should look like:

http://localhost:9000/account/foruser/something/0

and route (of course this need to be placed in one line in routes file:

GET     /account/foruser/:username/:create
   controllers.user.UserController.foruser(username: String, create: Integer ) 

Note that was some bug reports on using the Boolean type in the route, so it's just safer to use some numeric type instead.

like image 141
biesior Avatar answered Sep 24 '22 17:09

biesior


@biesior I am getting the same problem using 2.0.4 with two types of parameters

File routes:

GET /v2/object/all/data/:from/:until/:all           controllers.ObjectController.getAllData(from: String, until: String , all: Boolean, username: String ?= null, password: String ?=null)

File controller:

public static Result getAllData(
            @PathParam("from") String from,
            @PathParam("until") String until,
            @PathParam("all") Boolean all,
            @QueryParam("username") String username, @QueryParam("password") String password)

After doing several tests I finally solved the problem. You should use "boolean" instead of Boolean, so "getAllData" transforms to:

public static Result getAllData(
            @PathParam("from") String from,
            @PathParam("until") String until,
            @PathParam("all") boolean all,
            @QueryParam("username") String username, @QueryParam("password") String password)
like image 44
gavioto Avatar answered Sep 23 '22 17:09

gavioto