Taking the Java computer-database sample as a starting point in Play! 2.1 I'm developing a CRUD admin backend for about 20 models. The problem I'm facing is the repetition at the template level of the same functions over and over.
I have tried to refactor the link function as:
@****************************************
* Helper generating navigation links *
****************************************@
@link(newPage:Int, newSortBy:String) = @{
// Generate the link
controllers.admin.routes.Model.index(newPage, "id", newSortBy)
}
To something like
@(controller: Any, newPage: Int, newSortBy: String)
any.index(newPage, "id", newSortBy)
Since the reverse routers do not inherit from any specific class, I can't do it in a generic way. And the previous code doesn't work since I don't do a type casting (I guess since the compiler error is "value index is not a member of Any")
Is there any way I can get a list of the defined routes during runtime? Doesn't matter if it is in the Scala template or the Java side, that way I can pass a controller name and get the correct reverse router to create the URL.
If it is not possible, then what is the correct way to refactor all that code that repeats over and over the templates, specifically the ones that depend on the ReverseRouters.