5
votes

I'm a newbie at Java and I'm using the play framework 2.0 for a project and was wondering how to use the reverse routing functionality. We have the following:

In the routes file

GET /                controllers.Application.index()
GET /myapp/storage   controllers.myapp.AnotherController.index()

So to use reverse routing:

controllers.routes.ref.Application.index() 

but what about AnotherController?

If I use controllers.routes.ref.AnotherController.index() in a test, the play framework will throw an error "cannot find symbol".

Thanks.

2
Why not just place your AnotherController.java within the app.controllers package as well? - Jeff LaJoie
I was hoping to group controllers into individual packages. When making the GET request with the defined route "GET /test controllers.myapp.AnotherController.index()" the play framework resolved it without an issue. So I was hoping the reverse routing would also work with this setup. - user2288625
And did you try ontrollers.routes.ref.myapp.AnotherController.index() ? - ndeverge
Yes I tried controllers.routes.ref.myapp.AnotherController.index() and it reports cannot find symbol myapp. What avik suggested worked perfectly ... controllers.myapp.routes.AnotherController.index. - user2288625

2 Answers

12
votes

Try dropping the ref element. I use the following structure for reverse routes in my play-2.0.4 app:

<full-package-name>.routes.<controller>.<action>

So the reverse route to your second action would thus be:

controllers.myapp.routes.AnotherController.index()

Given that your action takes no parameters, I guess you can also drop the brackets:

controllers.myapp.routes.AnotherController.index
1
votes

In this way worked for me. I don't know why:

activator clean
activator run