I am working on Play Framework 2.0 for Java and I have a querystring url like http://localhost:9000/project/detail?id=1
, when this url hits It will call a HTML template file eg. detail.scala.html
. So I want to check is there querystring exist in url in my HTML file.
ex:
@if(existsQueryString)
@showPerticularProductDetail
else
@showAllProductList
Please help me or give any suggestion for this. I dont want to pass some variable or any flag from controller to view for checking the condition. I just want to check is querystring there in url inside my HTML.
You can access the request either directly if you're in a Java project, or via an implicit parameter if you are in a Scala project.
In a Java project, you can use it directly to check the queryString :
@if(request.queryString.containsKey("myKey")){
@showPerticularProductDetail
else
@showAllProductList
If you're in a Scala project, you need to add the request as an implicit parameter of your view :
@(title: String)(implicit request: play.api.mvc.Request)
And your controller should also declare this implicit parameter :
def detail = Action { implicit request =>
...
myTemplate.render()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.