user1197252
user1197252

Reputation:

Getting URL of current page loaded

I am asking this question because it is loosely related to another one of my posts.

Is it possible in the play framework (2.0.4) to retrieve the URL of the page currently loaded? For example if I want to modify this method:

        @Override
            public Call afterAuth() {

       *IF CURRENT URL = "localhost:9000/mobile" 

                    return routes.Application.mobile_index();

       *ELSE*

                    return something.else;
            }

Upvotes: 2

Views: 1209

Answers (1)

Gregory Kalabin
Gregory Kalabin

Reputation: 1788

You can use Request instance to get url relative of your host:


public static Result someControllerMethod() {
  String uri = request().uri();
  if (routes.Application.mobile_index().url().equals(uri)) {
    return ok(views.html.mobile_main.render());
  } else {
    return ok(views.html.index.render());
  }
}

Actually I don't know details about your application architecture, but you can pass Http.Context to your login handler.

update I don't familiar with play-authenticate module. I just looked at this source and have no idea how to access Http.Context in Resolver methods. I found only this question where presented some workaround, but it doesn't look like an elegant solution.

Upvotes: 5

Related Questions