I am trying to make some Javascript Rounting in my Play Framework app and am running into some errors:
I have a button with the id #next which should use Ajax to load some new image and text into a div named #content.
In my Application.java I have implemented the following two methods:
public static Result nextUser(int i) {
return ok(content.render(users.get(i)));
}
public static Result javascriptRoutes() {
response().setContentType("text/javascript");
return ok(
Routes.javascriptRouter("jsRoutes",
controllers.routes.javascript.Application.nextUser()
)
);
}
Made this content.scala.html file:
@(user: User)
<img id="user" src="@routes.Assets.at(user.getImg())" />
<h2>@user.getStatus()</h2>
Added this into to the routes file:
GET /nextuser controllers.Application.nextUser(i: Int)
GET /assets/javascripts/routes controllers.Application.javascriptRoutes()
And then tried this Javascript code:
<script type="text/javascript" src="@routes.Application.javascriptRoutes()"></script>
<script>
var userIndex = 1;
$("#next").click(function() {
jsRoutes.controllers.Application.nextUser(userIndex).ajax({
success : function(data) {
$("#content").html(data);
},
error: function(err) {
}
});
});
</script>
In the Application.java file in the javascriptRoutes Method the controllers.routes. can not be found.
Does anybody know what is causing the error?
Edit:
I could solve the initial error thanks to this: Unable to resolve reverse routing methods in IntelliJ
Now it looks like this:

The nextUser Method cannot be found even when cleary defined.
When I compile the application using activator compile and run it using activator run my chrome console looks like this:

so still the routes file somehow cant be found.
JavaScriptReverseRouteras described in the docs: playframework.com/documentation/2.5.x/… -- note that the embedded router does not with methods having parameters; you really have to use theJavaScriptReverseRouter. - koppor