10
votes

Does Play Framework 2.0 have any built-in equivalent to 1.2.x's jsAction?

If not, how can I create such a tag?

Update: Thanks to Julien Richard-Foy who got me on the right track, I was able to use javascriptRouter. However, Play 2.0 doesn't provide any examples on how to use it in their manuals, so I made an example on how it is used in Java.

2

2 Answers

8
votes

Yes, there is a play.api.Routes object providing a way to generate a JavaScript reverse router. There also is a template tag, helper.javascriptRouter, which can be used directly in the templates.

3
votes

For scala:

def javascriptRoutes() = Action { implicit request =>
    Ok(
      Routes.javascriptRouter("jsRoutes")(
        // Routes
        controllers.routes.javascript.Application.xxx,
        controllers.routes.javascript.Application.yyy
      )
    ).as(JAVASCRIPT)
  }

and in your template

<script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>

routes usage is explained at @Franz his blog: http://franzgranlund.wordpress.com/2012/03/29/play-framework-2-0-javascriptrouter-in-java/