cmsantos
cmsantos

Reputation: 327

Scala parameter to Java (Play Framework)

Is there a way to pass the value from a Scala parameter to Java on the view using the Play Framework?

Something like:

<strong>Title: </strong> @addtitle              

<a href="@routes.Application.shopping()" value="Add to Cart"
   class="btn btn-primary btn-xs">@Messages("playauthenticate.results.shopping")
</a>

But I wanna put the @addtitle as a parameter to the @routes.Application.shopping(@addtitle)

I'm using Play Framework 2.2.0.

Upvotes: 1

Views: 94

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

Yes there is.

Let's say your Application controller in the controllers package had a function with this signature:

public static Result index(String name) { ... }

or (in Scala)

def index(name: String) = Action { ... }

And you wanted the reverse router to produce the URL to this controller function from within the view:

@routes.Application.shopping(addtitle)

Notice how we don't need the @ symbol within the arguments of the function. It's already understood by the template compiler that it's reading scala, and not raw text. This is of course, not limited to the reverse router, but any function.

Upvotes: 1

Related Questions