Saturday, December 24, 2011

[Play!] How to use URL arguments to list multiple match results ?

You can even create a List from the arguments in the URL with the following line of code in conf/routes:

GET /showUsers/{<[\0-9]+>ids}/? Application.showUsers

In your application code you know you could use a List IDs and show several users at once, when the URL /showUsers/1234/1/2 is called. Your controller code would start like this:

public static void showUsers(@As("/") List ids) {
}

This introduces some new complexity in your application logic, so always be aware if you really want to do this. One of the usecases where this is useful is when you want to use some sort of hierarchical trees in your URLs, like when displaying a mailbox with folders and arbitrary
subfolders

No comments: