URI pattern in queryString

854 views
Skip to first unread message

Thijs

unread,
May 11, 2011, 10:36:00 AM5/11/11
to play-fr...@googlegroups.com
In the route file I can define:
/clients/{id} which results in /clients/123

Is there a way to use these parameters in the queryString, for example:
/clients?{id} which results in /clients?id=123

for multiple query string parameters this could be used
/clients?{id}&{name} which results in /clients?id=123&name=bob

Erwan Loisant

unread,
May 11, 2011, 10:40:38 AM5/11/11
to play-fr...@googlegroups.com

This is pretty much how it works already if you just use:
/clients
...parameters from the querystring will be bound to actions parameters.

> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> 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.
>

--
Erwan Loisant

Thijs

unread,
May 11, 2011, 10:50:45 AM5/11/11
to play-fr...@googlegroups.com
I want to use this with routeArgs.put("id", 123)

RouterArgs can only be referred to in the path of an url, not in the queryString.

Gaetan Renaudeau

unread,
May 11, 2011, 10:55:46 AM5/11/11
to play-framework
Play handle this for you

As Erwan said, you only need to add :
/clients
in your routes.

After that, the /clients?id=123 route is similar to /clients/123

Thijs

unread,
May 11, 2011, 11:12:36 AM5/11/11
to play-fr...@googlegroups.com
This is not true, when I have a controller that does this: routeArgs.put("id", 123)
The id is not appended to the queryString of the following route:
GET /clients Clients.show

It is append however if I define:
GET /clients/{id} Clients.show

All good you would say, except for the fact that I want it in the queryString instead of the path, so I'm looking for something like:

GET /clients?{id} Clients.show

Gaetan Renaudeau

unread,
May 11, 2011, 11:21:22 AM5/11/11
to play-framework
I don't understand your needs,
why are you doing routeArgs.put("id", 123) ?
Is it to resolve a url or generate it from the controller ?

Thijs

unread,
May 11, 2011, 11:29:33 AM5/11/11
to play-fr...@googlegroups.com
I want to use routerArgs because it's a global parameter which must be appended to all url's that have the {id} defined in the route file (this is exactly what routerArgs does).

Maybe my example is not very good, maybe this clarifies it:

In controller:
routeArgs.put("lang", "nl") 

GET /{lang}/clients Clients.show -> /nl/clients
GET /{lang}/products Products.show -> /nl/products

But what I want:
GET /clients?{lang} Clients.show -> /clients?lang=nl
GET /products?{lang} Products.show -> /products?lang=nl

Gaëtan Renaudeau

unread,
May 11, 2011, 11:35:07 AM5/11/11
to play-fr...@googlegroups.com
Remember that routes are independant. Play is stateless.
So for keeping informations like lang, you can : pass it each time your generate url in template but it's not very convenient
or put it in the Session object which is a signed cookie store on the client.

session.put("lang", "nl");

Regards,
gre

2011/5/11 Thijs <tsui...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
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.



--
---------------------------------------------------
site professionnel: http://pro.grenlibre.fr
blog: http://blog.grenlibre.fr
twitter: http://twitter.com/grenlibre
IM: grena...@gmail.com

Thijs

unread,
May 11, 2011, 11:46:05 AM5/11/11
to play-fr...@googlegroups.com
I don't want to use a session.

My point is the first example (variable in the path) is possible with Play! The only thing I want to do is move the parameter out of the path into the queryString. It's just cosmetics but it fits better my application.

Gaetan Renaudeau

unread,
May 11, 2011, 12:00:06 PM5/11/11
to play-framework
I don't understand the point of sometime having /clients/123 and
sometime /clients?id=123 in the URL. Anyway, It sounds impossible to
resolve, how Play could know which route to use ?

Julien Richard-Foy

unread,
May 12, 2011, 4:07:27 PM5/12/11
to play-fr...@googlegroups.com
IMHO, if the following route:
GET /clients Clients.show
Used after a call to `routeArgs.put("id", 42)` still produces the
"/clients" url, then it is a bug and should be reported in
lighthouseapp.
Reply all
Reply to author
Forward
0 new messages