emt14
emt14

Reputation: 4896

PLay framework Routing with multiple parameters issue

I don't seem to be able to resolve the following scenario where no routes are found.

Got my route file with the following entry:


GET     /reports/items/{date}                          Reports.items(field:'all')

and the controller defined with


public static void items(@Required Date date, String field){
...
}

the view is using @{items(date)} or @{items(date,'all')}

the url translates to: localhost:9000/reports/items/19-07-2011?field=all

I always seem to get not found with:


tried the following route
GET       /                                                 Reports.index
GET       /reports/items/{date}                             Reports.items 

Any idea on how I can route and default field to 'all' if it is not provided?

Upvotes: 2

Views: 1342

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

I believe what you need is this:

GET       /reports/items/{date}                     Reports.items(field:'all') 
GET       /reports/items/{date}/{field}             Reports.items 

First the system will match the request with only date (which will use 'all' as default value for field).

If it doesn't match, because you added the field, it will go to the second GET where both parameters will be mapped to the controller.

Upvotes: 3

Related Questions