Play Framework: redirecting to a controller method with arguments

I am creating a web application with PLAY framework 2.2.1 and trying to display all the available http get query parameters for the requested site in the address bar, even those that are not specified in the request. In cases where not all http get parameters are available, I want to add uninstalled parameters with default values ​​and redirect.

I have a website that can be requested using GET:

GET /test controllers.Application.test(q:String, w:String ?= null, f:String ?= null, o:String ?= null) 

Here is the method I would like to have in controllers.Application :

 public static Result test(String q, String w, String f, String o){ ... // In case not all parameters where set if (reload == 1){ return redirect(controllers.Application.test(qDefault, wDefault, fDefault, oDefault)); } else { ok(...); } } 

The problem is that redirect () accepts a String object, not a Result object.

My first decision is to write

 return controllers.Application.test(qDefault, wDefault, fDefault, oDefault); 

But, unfortunately, the address bar is not updated.

My second solution is to create a string manually:

 return redirect("/test?q=" + query + "&f=" + f + "&w=" + w + "&o=" + showOptions); 

This works great, but is there no other way to a more elegant way to do this?

+6
source share
2 answers

Use the routes object:

 public static Result index() { return redirect(controllers.routes.Application.test(qDefault, wDefault, fDefault, oDefault)); } 

Source: Official Documentation

+8
source

In addition, this is also true.

 public static Result index() { return redirect("path"); } 
+1
source

All Articles