Is it possible to generate an url mapped by an object ?
The Pojo Object Mapping is a native function of PlayFramework (1.2.2), but what about the reverse routing?
I would like to do this :
Java:
class MyControler extends Controller {
public static function myAction(MyObject o) {}
}
Route: (something like this ? If it’s possible, i don’t know the syntax to do it !)
GET /folder/{myObject.name}/{myObject.id} MyController.myAction(myObject)
Template :
<a href="@{MyControler.myAction(myObject)}">Go</a>
Expected result :
<a href="/folder/xxNamexx/33">Go</a>
(I have a Symfony background, and I search an equivalent to the Object Route Class)
I think Play! don’t support this functionnaly, could someone confirm or refute this idea?
Thank you.
According to Julien Richard-Foy, there is no solution.
So I propose a workaround, a little ugly because the route will be describe twice.
This quick solution breaks the MVC model, but it’s possible to do otherwise, sending a UrlHelper to the template for exemple.
In your model, add a
generateUrlDetail()method :Tips : Play! allows to define a route with more identifiers than necessary. So it’s possible to write a route with 2+ variables, but only the ID will be used in the action.
And in your template :
And it works 🙂