Routes with multiple parameters in Play 2.0

2,482 views
Skip to first unread message

Edmondo Porcu

unread,
Mar 30, 2012, 10:47:16 AM3/30/12
to play-fr...@googlegroups.com
Dear all,
I don't find in the documentation how to have routes with multiple
parameters which are automatically passed to the controller in Play
2.0

What is the right syntax to add a route in routes in play 2.0?


Best Regards
Edmondo

biesior

unread,
Mar 30, 2012, 10:53:21 AM3/30/12
to play-fr...@googlegroups.com
GET     /something/:id/:name       controllers.Controller.action(id:Long, name:String)

Edmondo Porcu

unread,
Mar 30, 2012, 11:57:56 AM3/30/12
to play-fr...@googlegroups.com
I am confused, will that match
/something?id=10&name="James" ?
or
/something/10/james

I am trying to match the first of the two...

Best Regards


2012/3/30 biesior <bie...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/qjmBU5G1PFYJ.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.

biesior

unread,
Mar 30, 2012, 1:14:15 PM3/30/12
to play-fr...@googlegroups.com

it will match second case

Other case:

GET     /nice-test/:id/:name   controllers.Application.test(id:Long, name:String)
will match /nice-test/10/james

and

GET     /ugly-test             controllers.Application.test(id:Long ?= 0, name:String ?= "")
will match /ugly-test?id=10&name=james


they both will be passed correctly to the same action, but ugly case is just ... ugly:

    public static Result test(Long id, String name){
        return ok("The "+name+" has id "+id);
    }


What's more in your view you should build url for both cases in the same way:

<a href="@routes.Application.delete(user.id, user.name)">Show me user</a>


W dniu piątek, 30 marca 2012, 17:57:56 UTC+2 użytkownik edmondo1984 napisał:
I am confused, will that match
/something?id=10&name="James" ?
or
/something/10/james

I am trying to match the first of the two...


2012/3/30 biesior

biesior

unread,
Mar 30, 2012, 1:17:29 PM3/30/12
to play-fr...@googlegroups.com
arrggghhhh sorry! that shoul be this link of course

<a href="@routes.Application.test(user.id, user.name)">Show me user</a>
Reply all
Reply to author
Forward
0 new messages