FAQ Database Discussion Community


Play Framework with IntelliJ Community Edition 14

intellij-idea,playframework-2.0
I have not managed to compile/debug etc. the current Play Framework (2.3.7) with the Community Edition 14 of IntelliJ. Neither by importing the project, nor by using gen-idea . Is there any way to get it run or is there just no way to use it ? Paying > 400...

Setting up play framework and dart for development and debug

eclipse,playframework-2.0,dart,dart-pub,typesafe-activator
I'm developing a relatively simple web app using play framework for the server and dart for the client. I'm using eclipse. Development and debug are fine on their own but how do to get them to work together? Play has its own web server (activator) that knows how to load...

Suddenly unresolved dependency echo-trace-play echo-sigar-libs

java,playframework-2.0,sbt,typesafe-activator,typesafe
Yesterday my activator started updating all of the sudden and in the end I got this error: Read from stdout: (:update) sbt.ResolveException: unresolved dependency: com.typesafe.trace#echo-trace-play-2.3.9_2.11;0.1.15: not found Read from stdout: unresolved dependency: com.typesafe.trace#echo-sigar-libs;0.1.15: not found (:31mupdate0m) sbt.ResolveException: unresolved dependency: com.typesafe.trace#echo-trace-play-2.3.9_2.11;0.1.15: not found unresolved dependency: com.typesafe.trace#echo-sigar-libs;0.1.15: not found Already removed all...

Play Framework 2.x Ebean query ManyToMany for all

java,orm,playframework-2.0,ebean
I have two models in Play Framework 2/Ebean, 'Article' and 'Tag', which has a ManyToMany-relationship to each other. Article: @Entity public class Article extends Model { @ManyToMany List<Tag> tags; // ... } Tag: @Entity public class Tag extends Model { @ManyToMany List<Article> articles; // ... } Given a List<Tag>, how...

Advanced HTTP server configurations in Play 2.3

playframework,playframework-2.0,playframework-2.2,playframework-2.1,playframework-2.3
I am using Play 2.3 to develop an application. I need to set http.netty.log.wire to true which is by default false as specified in Play documents. In the below link (last section) it says this option is available but it also specifies "we cannot use application.conf" to specify this. https://www.playframework.com/documentation/2.3.x/ProductionConfiguration...

Set Transaction isolation level Play Framework 2.3

playframework-2.0
How can I set transaction isolation level in Play Framework 2.3? Currently it doesnt seem to be possible to set on the @play.db.jpa.Transaction annotation

How to get response session cookie in Jquery

javascript,jquery,cookies,playframework-2.0,session-cookies
I need to get response session cookie in JQuery. I need to know if session has expired and I believe the only way to do is to check whether response from server contains session cookie I am using play framework in backend which doesnt preserve session details at backend and...

Unresolved dependency error with SecureSocial

java,playframework-2.0,sbt,securesocial
I require Secure Social Plugin [http://securesocial.ws/guide/installation.html ] for my project. When I run the play 2 app I am getting the following error. I also referred the following post: Why is the Unresolved Dependencies error with SecureSocial and Play 2.3.2? [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: UNRESOLVED DEPENDENCIES :: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn]...

How does @Inject in Scala work

scala,playframework,dependency-injection,playframework-2.0
I'm wondering how does @Inject annotation in Play-Scala works. It obviously injects a dependency, but I'm curious how is it working. When I was using it on class extending controller and set routes generator to injectroutesgenerator it seems to autmagically create objects from those classes, but how do I use...

In the Play Route's file, how can indicate to use routes from a module?

scala,module,compiler-errors,routes,playframework-2.0
Currently trying to follow Manning's Play for Scala, specifically the section on testing a module before publishing. I've created a module named "Ean2BarcodePlayModule" with organization "net.nowhereatall.playforscala". I've used activator to publish local to ~/.ivy2/local In my test project, I've added the library dependency: "net.nowhereatall.playforscala" %% "ean2barcodeplaymodule" % "1.0-SNAPSHOT" Now, I'd...

How to remove warning regarding the use of status code 200 with flashing in Play 2.3.7?

playframework-2.0
I have just updated my play-example-form application to work with Play 2.3.7. It went very smoothly, but now when I run the application I get the following warning in my console: [warn] play - You are using status code '200' with flashing, which should only be used with a redirect...

Dependent futures

scala,playframework-2.0,future
Starting playing with Scala futures, I get stuck with dependent futures. Let's get a example. I search for places and get a Future[Seq[Place]]. For each of theses places, I search for the closest subway stations (the service resurns a Future[List[Station]]). I would write this: Place.get() .map { places => places.map...

Activator throws IllegalArgumentException: URI has an authority component

playframework-2.0,sbt,typesafe-activator,activator
I'm developing a project in Play 2.4, and I run it using the activator UI. I recently had to forcibly stop the app by pressing "Stop" on the UI, and I haven't been able to get it to work since. Now, on ANY project I open using activator, it never...

convert play framework route to java URL class (used to initialize java.net.URL class)

java,playframework,playframework-2.0
I want to play song in page when it opening. (I know It's a bad idea but I want to say Happy Birthday to my cousins :D ) for that I need to convert play framework routes to java.net.URL class. I tried these line of code but all of them...

How to send json string body for FakeRequest without using withJsonBody in Play framework v2.x?

json,scala,testing,playframework,playframework-2.0
I have play scala v2.3 application. I'm trying to create a controller test by sending json string with FakeRequest as below: class ApplicationSpec extends Specification { "Application" should { "Create Bob Test" in new WithApplication { val jsonStr = """{"text": "hi bob"}""" val result = route(FakeRequest(POST, "/bob") .withHeaders("Content-Type" -> "application/json")...

Play Framework app can't be deployed when ssh session stopped

scala,ubuntu,playframework-2.0,server,production
I am trying to deploy a play framework app on my remote virtual private server hosted by OVH. My VPS is on ubuntu 14.10 server. Therefore, I read the documentation and I used the command line: activator start instead of activator run to deploy in production my app. I can...

No Json formatter found for type Seq[models.Comment] Try to implement an implicit Format for this type

scala,playframework,playframework-2.0
Hello scala and playFramework gurus, I don't understand why usage of implicit Json.format[Comment] does not work in my code. From the docs description it should works as Format[Comment] but looks like it doesn't. Here is code of my two case classes with their companions case class ServiceTask(id: Option[String], name: String,...

How to serve reactive ByteChunks in Play Framework (Java) v2.4.x

java,playframework,playframework-2.0,reactive-programming
I have a working code base that serves Chunks<byte[]> wrapped in an HTTP status 206. The code streams an .mp3 file to the browser. public class ChunksController extends Controller { private static byte[] song; private static RangeWrapper range; private static Chunks<byte[]> chunks; @With(MP3Headers.class) public static F.Promise<Result> handler() { return F.Promise.promise(new...

Table creation in play 2.4 with play-slick 1.0

scala,playframework,playframework-2.0,slick,slick-2.0
I got the play-slick module up and running and am also using evolution in order to create the required tables in the database during application start. For evolution to work it is required to write a 1.sql script which contains the table definitions that I want to create. At the...

run ionic framework with play! framework locally

playframework-2.0,ionic-framework
I've developed a little ionic app. I've tested it using "ionic serve" and with Play framework running locally on my machine and everything works fine. Now I would like to do the same thing while emulating my app with "ionic emulate iOS", but if I try this combination my app...

Play 2: How can I get an URL with parameters that aren't encoded when reverse routing?

routing,playframework-2.0,url-encoding
This my route: GET /login controllers.Auth.login(from: String ?= null) So, when I do this: public Result onUnauthorized(Http.Context context) { return redirect(controllers.routes.Auth.login(context.request().uri())); } I get: mydomain.com/login?from=%2Fmy%2Fpage But I want the URL to look like this: mydomain.com/login?from=/my/page I can obtain this nice url, readable by anyone, doing this: public Result onUnauthorized(Http.Context context)...

Play Framework withCookies but no cookies in client document

playframework,playframework-2.0
I have a simple controller object Application extends Controller { def index = Action { Ok(views.html.index("Your new application is ready.")).withCookies(Cookie("Key", "Value")) } } Everything is setup properly (routes, index.scala.html ...) The "index" triggers the following JavaScript code. console.log("thecookies: " + document.cookie); (There is no more code) The output is only...

Play 2 - Access conf property in routes file

java,playframework,routes,playframework-2.0
In older version of play, we could have written the following code in routes with somevar being defined in application.conf %{ somevar = play.Play.configuration.getProperty("somevar") }% GET /${somevar} controllers........ So we could have accessed the value of somevar in routes Can anyone help me in accessing properties in routes from application.conf...

Traversing multiple JSON arrays in Play/Scala

json,scala,playframework,playframework-2.0,scala-2.10
{ "location":{ "residents":[{ "renting":[{ "name":"John Doe" "pets":"2" },{ "name":"Jane Smith" "pets":"2" }] }] } } I can successfully traverse location with this - val json = ... val rentReads = (__ \ 'location).read[String] val rentResult = json.validate[String](rentReads) rentResult match { case s: JsSuccess[String] => Ok(s.get) case e: JsError => Ok("Errors:...

Issue on saving data into DB using play / Ebean

java,playframework,playframework-2.0,ebean,playframework-2.3
I have 3 classes. Car User UserCars This 3 classes represents tables into my DB. The UserCars table links the Car and Users table and it's constructed the following way: ---Users--- int id int cars_id int user_id ----- I try to save a car related to it's user by using...

How to mock an Authenticator in play framework with guice injections?

java,playframework,playframework-2.0,guice,guice-3
I have a play application with authenticated routes. I implemented an Authenticator, storing users into elasticsearch. My securized methods in my controllers are annotated with the @Security.Authenticated annotation. For my unit tests with mockito, I would like to mock this class but I don't know how to do this. I...

Nested Async calls using Scala and Play Framework?

scala,cookies,asynchronous,playframework,playframework-2.0
I would like to make nested asynchronous calls. I would like to perform one async call before I make a 2nd async call. The 1st async call will dictate what parameters or actions to take with the 2nd async call. Here's the original async call: def render(param1:String) = Action.async {...

Java - Getting the URL's parameter

java,url,parameters,playframework-2.0
I have a URL something like this I'm using play framework HTTP Routes: GET /students controllers.Application.Get() POST /students controllers.Application.Post() PUT /students/{studentNo} controllers.Application.Put() How will I get the {studentNo} value? For example I'm using a postman(rest client) and I typed something in the url http://localhost:9000/students/2012111222 , how will I get the...

If statements within Play/Scala JSON parsing?

json,scala,playframework,playframework-2.0
Is there a way to perform conditional logic while parsing json using Scala/Play? For example, I would like to do something like the following: implicit val playlistItemInfo: Reads[PlaylistItemInfo] = ( (if(( (JsPath \ "type1").readNullable[String]) != null){ (JsPath \ "type1" \ "id").read[String]} else {(JsPath \ "type2" \ "id").read[String]}) and (JsPath \...

Where to put user uploaded files in play framework?

java,playframework,playframework-2.0
There is the possibility in my web App that the user can upload different files. the files are not stored in the DB, but in the file System. but I don't want them to be accessible publicly (only throw my Controller). is there any difference between storing the files in...

How to make route method works in Play 2.x sub-project?

scala,testing,routing,playframework-2.0
I have a Play 2.3 project with a sub-project inside. Following this tutorial, I am writing a test for sub-project's controller with route method: "Get Action" in new WithApplication { val Some(result) = route(FakeRequest(GET, "/sub/bob/11")) status(result) mustEqual OK } Assumed in routes.conf, the sub-project routes is configured like this: ->...

Generating a link to a controller action in Play Framework 2.3

html,scala,playframework-2.0
I'm working on a Play application and need to generate links in a mixed Scala-HTML view that call controller actions. I found this question from a couple years ago that's similar to my situation, but the provided answers don't work for me. The elements are generated in a loop so...

Filter a string before creating an Option[String]

scala,playframework-2.0,playframework-json
I have the following where obj is a JsObject: val approx_pieces: Option[String] = (obj \ "approx_pieces").asOpt[String] This code will create a Some("0") if the approx pieces is "0" in the database. How can I change it so that it creates None when the string is "0"?...

Play Scala 2.4 linking asynchronous calls

scala,asynchronous,playframework,playframework-2.0
I'm trying to figure out how to link multiple asynchronous calls and return a result. I am currently trying to asynchronously user data first, and update user data asynchronously and return result, but it seems like it is not working :( i used map { result => Ok(result)}, but play...

Trouble with Hibernate Entity in Play 2.4

java,hibernate,playframework-2.0
I'm trying to use JPA in Play 2.4, but it's flinging errors at every step of the way, none of which seem to be well documented. I have a test Entity here: @Entity @Table(name="testit") public class TestModel { @Id private long id; private String title; public TestModel(String title) { this.title...

Return type of bindFromRequest.fold

scala,playframework-2.0
My feeble Scala skills have me baffled about the right way to do something. The code below compiles (and works) only when I include the t match {... line. If I eliminate that line and of course, the diagnostic println on the preceding line, I get the compile time error...

Play: populating a helper select from Java

java,scala,playframework,playframework-2.0,template-engine
I have to populate an HTML select with ids and labels. I also need the labels to be ordered alphabetically. If I pass a List<String> of labels, I lose ids. If I pass a Map<String,String>, I have ids, but the ordering is not kept. My page: @(countries: Map[String,String], myForm: Form[JUG],...

Java / Ebean And Or Query

java,playframework-2.0,ebean
I'm trying to perform an sql query as so: select * from conversations where (user_1 = user_1_id and user_2 = user_2_id ) or (user_1 = user_2_id and user_2 = user_1_id ) I'm writing it in Ebean as so: Conversation conversation = Ebean.find(Conversation.class) .where() .and(Expr.eq("user_1", user_1_id), Expr.eq("user_2", user_2_id)) .or(Expr.eq("user_1", user_2_id), Expr.eq("user_2",...

Why are some things defined twice in Scala's libraries?

scala,playframework,playframework-2.0,akka
I find some libraries for Scala (including its own library) organised in such a messy way that really bothers me and makes things hard to remember. I'm coming from a .NET background where everything is so easy to pick up and there are no "gotcha's". One example I can remember...

Change plays default port doesn't work

playframework-2.0
When I'm on my mac I can start the server like this activator start -Dhttp.port=9090 Now when I do this on the windows 2012 server I get that the command isn't valid. How can I change the default port on Windows then?...

activator dist: Not include managed resources (only their processed result)

playframework,playframework-2.0,typesafe-activator
How do I avoid the inclusion of managed resources, such as sass files from the zip output of activator dist? I manually deleted them from the target directory in my project such that my project now has no trace of scss files inside the target directory. But that still includes...

Play! Framework support for Java 8 Optional

java,playframework,playframework-2.0,java-8
I've got a Play! 2 routes file and controller that looks something like this: GET /books BooksController.getBooks(author: play.libs.F.Option[String]) public class BooksController extends Controller { public static Result getBooks(play.libs.F.Option<String> author) { ... } } I would like to refactor it to use Java 8's Optional, but this causes a compilation error:...

Scala Standalone WS with Authentication

scala,playframework-2.0
I would like to use the WS client from play framework without an running PlayApplication. So I imported the WS lib only in my build.sbt with: "com.typesafe.play" %% "play-ws" % "2.3.7" My example standalone application looks like: object WetherWSClient extends App { val builder = new AsyncHttpClientConfig.Builder(); val wsClient =...

Scalastyle “Public method must have explicit type” in Play Framework

scala,playframework,playframework-2.0,scalastyle
We've started experimenting with Scala and the Play framework at my work. Setup our auto-linting and testing framework as the first thing, and have deployed Scalastyle to handle the former. That has been very useful, except that we are getting this specific lint error that we are finding it difficult...

What is data type of the input of withFormUrlEncodedBody?

scala,playframework-2.0
def MakeRequest(method:String,url:String, data : Map[String,String]) = { route(FakeRequest(method,url).withHeaders("X-Requested-With" -> "1").withFormUrlEncodedBody(data)).get } The error is at withFormUrlEncodedBody(data). It says that expected (String,String), actual: Map[String,String]. What exactly (String,String) data type? I used data:(String,String) but the input only accepts 1 mapping. It would accept muptiple mappings. The following code is working without passing...

Using SORM with Play Framework 2.3.8

scala,playframework-2.0,sorm
I am going through the Video introduction to Play Framework and, but I am stuck creating a DB object with SORM because the import fails. I tried to add the dependencies in plugins.sbt, and relaunched activator, but it seems that activator cannot find the dependencies and I get and I...

Which scala version uses Play! framework 2.1?

playframework-2.0
I have a Java Play! project. When I import it to IntelliJ I can see in my target folder a scala-2.10/ folder. But when I look in my project/target/ folder, I have a scala-2-9-2 folder. How comes this and how to know which scala version is really used ?

Trouble understanding WS library in Scala

scala,playframework-2.0
I'm trying to learn scala with the play framework and I'm trying to rewrite an old project completely in scala for practice. I have written a route that registers a new subscriber and sends them a thank you email for subscribing, using mandrill. I also have some basic error checking...

What is the difference between play.plugins and plugins.sbt?

plugins,playframework-2.0,sbt
In a Play! app (Play 2.3), sometimes I see a plugin enabled by adding an addSbtPlugin entry in file project/plugins.sbt. For other plugins that I made by extending the Plugin trait, I have to add a conf/play.plugins file to register the plugins. Are these 2 ways to achieve the same...

Play framework: is there a way to avoid strange form helper syntax?

java,forms,scala,playframework,playframework-2.0
I am trying to build a form with Play Framework 2, the usual syntax is: @helper.form(action = routes.Application.submit, 'id -> "myForm") { } Note that the single quotation mark is before id is opened and never closed. Is there another syntax that I can use to do the same thing?...

Error passing parameters in play framework

playframework,playframework-2.0,environment-variables
I have a play framework with one of the config file pointing to redis configuration. redis.host="$IP_ADDR" where IP_ADDR=XXX.XXX.XX.XX(in environmental variables) The error message is Caused by: java.net.UnknownHostException: $IP_ADDR Q1)Why is it pointing to $IP_ADDR when it should point XXX.XXX.XX.XX? When I run in shell with sh run.sh -Dredis.host="$IP_ADDR" it is...

Result to Map in Scala Anorm

scala,playframework-2.0,anorm
I am trying to get a map of name -> id from the resultset. val isp = SQL("select id, name from internet_service_providers").map { x => x[String]("name") -> x[String]("id") } I am unable to understand why I am getting this error. Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object; at anorm.SqlStatementParser$$anonfun$3.apply(SqlStatementParser.scala:43) at anorm.SqlStatementParser$$anonfun$3.apply(SqlStatementParser.scala:43)...

Play Scala activator compile command shows value userid is not a member of play.api.data.Form[models.Changepas sword]

scala,model-view-controller,playframework,playframework-2.0,typesafe-activator
I am new to play framework(Scala),In my project I need to update new Password for this I need to get user id which is Primary key for that user table. Based on this unique user id value i will update Password. What I need need to get user table's user...

missing arguments for method apply… Play Framework 2.4 compilation error

scala,playframework-2.0
Compilation error: missing arguments for method apply in class newPost; follow this method with `_' if you want to treat it as a partially applied function I don't understand how template handling methods have to look like and what complier require of me. https://github.com/flatlizard/blog controller: def addPost = Action{...

Play framework: package javax.inject does not exist

java,build,playframework-2.0,sbt,dependency-management
In my Play 2.0 Framework Java project, the following line yields errors both in Eclipse and during the sbt compile step: import javax.inject.*; I already added the javax.inject dependency to my build.sbt file: libraryDependencies ++= Seq( javaCore, javaJdbc, javaEbean, javaWs, javaFooBar, cache, "javax.inject" % "javax.inject" % "1", "org.atmosphere" % "atmosphere-play"...

CSS to conf/messages in play framework

java,css,intellij-idea,playframework,playframework-2.0
I have messages under conf directory of play framework. required.message=This field cannot be empty And in the model, I have: @Constraints.Required(message = "required.message") public String name; I am getting the messages properly on validation. What I want to do is, change the color of the messages. Currently I am getting...

Play framework Json output issue

json,scala,playframework-2.0
I have a simple action which outputs a json object string, like this: Ok(toJson(Map( "results" -> result_lists ))) This works all right. But if I do: Ok(toJson(Map( "action" -> action_string, // a Scala String "results" -> result_lists // a Scala List ))) I got No Json serializer found for type...

How to chunk responses in Play without running out of memory

playframework,playframework-2.0,playframework-2.3
I'm iterating over a large data set, with regular calls to play.mvc.Results.Chunks.Out.write(...) from within onReady. Because writes happen faster than data is sent to the client, I'll often run out of memory after a while... So what's the proper way to do this?...

How to send a parameter to a custom action?

scala,playframework,playframework-2.0
I am using action composition of play framework 2.3 and I would like to send parameters to the custom action. For example, if you have a custom action that adds a cache how the custom action can receive the cache key and the desired cache time. Example code inside a...

Sticky Cookies in Scala

javascript,scala,cookies,playframework,playframework-2.0
I've set a cookie in Scala similar to the following: val cookies:Seq[Cookie] = new Seq() val nDaysExpire:Int = 2000 val nSecondsExpire:Int = nDaysExpire * 24 * 60 * 60 val cookie:Cookie = new Cookie(sCookieID, sValue, Option(nSecondsExpire)) cookies = cookies:+ cookie Ok(views.html.main(sID)).withCookies(cookies:_*) and then I immediately delete the cookie in JavaScript....

scala json validation not working

json,scala,validation,playframework-2.0
I am following **Play For Scala ** for validation and parsing of Json I am receiving a request in controller after converting it to JsValue like this val jsonRequest = request.body.asJson.get i am trying to validate it like this jsonRequest.validate[ReadArtWorkCaseClass].fold( valid = { readArtWorkCaseClass => log.info("valid block") Ok("validation successful" )...

Google API: object oauth2 is not a member of package com.google.api.services

google-api,playframework-2.0,sbt,google-api-java-client,google-api-client
I'm developing a web backend using the Google APIs. In order to get the email address of a user, you have to send your access token to a Google tokenInfo service, that will return general information (including your email address). In general Google APIs do not return you the mail...

How can I retrieve the SQL table name in Slick 2.0

scala,playframework-2.0,slick,slick-2.0
I need to have access to the SQL table name and since my Slick scheme already stores it, I would like to access it directly through the slick object without having to store it twice. In Slick 1.0, this can be achieved with table.tableName assuming table is e.g. class MyTable...

Validate scala forms, when form contains inner case classes

forms,scala,validation,playframework-2.0
Help with Scala forms validation, Here is the case class for the form data: case class Data( firstName: String, lastName: String, email: String, confirm_email: String, password: String, confirm_password: String) } And the Scala Form: val form = Form( mapping( "firstName" -> nonEmptyText, "lastName" -> nonEmptyText, "email" -> email, "confirm_email" ->...

Maintenance mode for the Play Framework

playframework,playframework-2.0
Is there any way to enable the display of a static HTML page to explain that a site is in maintenance during times such as when the Play Framework is compiling new code? I can see how we could manually create a maintenance page for things such as while a...

Faking Ajax Request Form for testing

java,ajax,unit-testing,playframework,playframework-2.0
In my Playframework 2.4 project I have methods like this: public static Result resetValue(int client) { String receivedName= form().bindFromRequest().get("username"); User user = User.findByName(receivedName); if( user == null ) { return badRequest("No user logged in"); } user.setValue(0); user.saveUsertoDB(); return ok("Value set to zero"); } I want to write JUnit Tests for...

Scala play 2 framework how can I implement a write or format on Json

json,scala,playframework-2.0
I am new to Scala and play 2 and haven't found a way to return a Json request from the database using Anorm. This is my simple code def locations = Action {implicit c=> import play.api.libs.json._ implicit val readLocations = SQL("select city,state from zips limit 1") Ok(Json.toJson(readLocations)) } The method...

Defining cross-attribute Json Validators for a case class in Play Framework 2.3.x (Scala)

json,scala,validation,playframework-2.0,playframework-2.3
I know it's possible to define Case classes that we want to match some given json against (we use JsValue.validate[T]): For example: case class UpdateDashboardModel(id: Long, maybeName: Option[String], containers: Option[List[UpdateContainerModel]], description: Option[String]) And then we must write a Reads[T] to define how to actually turn a json object into an...

JSON Reads combinator in Play scala 2.x doesn't work for Map[String, _]

json,scala,playframework,playframework-2.0
I have a Play-scala v2.3 application. Looking from this guide about Json Combinators, I'm trying to do this: object Application extends Controller { case class Foo(id: String, docs: List[Map[String, _]]) implicit val fooReads = ( (JsPath \ "id").read[String] and (JsPath \ "docs").read[List[Map[String, _]]] )(Foo.apply _) ... } But then I...

Interchangeable menu in Scala Play

scala,playframework,playframework-2.0
At the moment I'm developing a web application using Bootstrap and Scala Play and I don't really understand the templating engine. I would like to have different Bootstrap navbars. The first one, if the user is not logged in yet. And a second view, when the user is logged in...

Play Framework building select options including a no-op option

scala,playframework,playframework-2.0
I'm creating a search form with a select element which has "Any" as the first option. The rest of the options are widget ids and names. The variable myWidgets is a list of three instances, the result I'm aiming for is along these lines: <select id="widget" name="widget"> <option value="-1">Any</option> <option...

Continuously-running code in Java Play! Framework

java,playframework-2.0
In the Play!-framework, code is triggered by requesting a URL from the server. The thing is, I need to have some code in the background running continuously from start-up, polling a database for new entries every few minutes, as if it were a normal program with a main() function. As...

IntelliJ Ultimate can't find routes in Play 2.3 (Java) project tests

java,intellij-idea,playframework-2.0,playframework-2.3
While my tests run just fine, IntelliJ complains that it can't find the routes object and code auto complete fails to work. I've looked all over the documentation and this should just work. Here is what IntelliJ is reporting Any thoughts as to what might be wrong with my project...

Elegant way of setting headers in Play Framework 2.4.x

playframework,annotations,http-headers,playframework-2.0
Is there a more elegant way to set the Content-Range, X-Content-Range and Content-Length headers in Play Framework 2.4.x? public static Result stream(Long id) { byte[] data = Song.get(id).getData(); RangeWrapper range = new RangeWrapper(request().getHeader("Range"), data.length); Chunks<byte[]> chunks = ByteChunks.whenReady(out -> { out.write(Arrays.copyOfRange(data, range.getFrom(), range.getTo())); out.close(); }); // Is there a way...

ScalaJson: Traversing JSValue structure (JSONPath syntax) where key might be one of two different strings

json,scala,playframework,playframework-2.0,jsonpath
I need to retrieve information from a JsValue that may be structured in a few different ways buy the specific values I'm looking for will always be under similar names. So for example I could have something like: { "name" : "Watership Down", "location" : { "lat" : 51.235685, "long"...

Play! framework Java Promise example

java,playframework-2.0,promise,java-7
I'm reading up on Java's Play framework but don't have much experience in Java. Can someone please explain this Promise<Double> promiseOfPIValue = computePIAsynchronously(); Promise<Result> promiseOfResult = promiseOfPIValue.map( new Function<Double,Result>() { public Result apply(Double pi) { return ok("PI value computed: " + pi); } } ); I get that they're creating...

Deploy Play! 2.2.x on java based shared hosting

playframework-2.0
Currently, I'm planning to deploy my Play! 2.2.x app on a shared hosting service. Since it's cheaper than to deploy it on cloud like heroku. I don't have any experience on deploying my app on java shared hosting, like tomcat and jetty. However, I do know that for tomcat and...

where is this 'helper' imported from in Play Framework

playframework-2.0
I am reviewing the Activator websockets template and there is the following view: @(message: String)(implicit request: RequestHeader) @import helper._ @main("Websocket Stateless DEMO") { where is this 'helper' import coming from? thanks...

Play Framework: Chain ActionsBuilder and ActionRefiner

scala,playframework,playframework-2.0,actionbuilder
I am desperate. I tried to do ActionComposition like in the very last paragraph of the official docs: https://playframework.com/documentation/2.3.x/ScalaActionsComposition My code: object ActionBuilder1 extends ActionRefiner[Request, Request] { override protected def refine[A](request: Request[A]): Future[Either[Result, Request[A]]] = Future {Right(request)} } object ActionBuilder2 extends ActionBuilder[Request] { def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result])...

Iterating cookies in Play+Java

java,cookies,playframework-2.0
I've been looking into managing the cookies stored by a play application. Ideally I'd like to iterate all of the cookies for that user and selectively remove some based on some conditions. Before I do that, though, I wanted to simply iterate the cookies to view them, such as: for...

Accessing h2-browser and debugging in play framework application

playframework-2.0
In play it is possible to access the h2-browser by entering the activator console and entering h2-browser. This will bring up a web interface to the h2 in memory database. Per the documentation, in order to debug an application you don't enter the activator console but instead run the command...

Making it easier to create a Form object in Play Framework with ReactiveMongo

mongodb,scala,playframework,playframework-2.0,reactivemongo
EDIT: For those who wonder how I plan to solve it according to the accepted answer, see Nested Values here. I'm using Play Framework with Scala and Reactive Mongo. Currently I'm creating my case classes and forms like this: case class Person( _id : Option[BSONObjectID], name: string, city: string) object...

Play upload File (Database and assets)

playframework-2.0
Users need to upload some images files from a form. This images files need to be saved to public/ folder. And i need to have a view to display this images too. (from URL ?, assets ?) How can i proceed ? I need to save the file name in...

In Playframework2, how to serve multiple asset directory?

scala,playframework,playframework-2.0,sbt,assets
There are two asset directory, one is /ui/dist and the other is /public. I tried to write the routes like this: GET /assets/*file controllers.Assets.at(path="/public", file) GET /ui/*file controllers.Assets.at(path="/ui/dist", file) But it will throws an error while compiling: [error] Unspecified value parameter file. [error] <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> Does anyone have...

Typesafe Activator: “run” works, but “start” fails with an error

java,scala,playframework-2.0,sbt,typesafe-activator
I'm working on a project, using Java Play-framework. Until now I always tested it by executing ./activator run, which worked flawlessly. Now, I wanted to try and deploy it by running ./activator start instead. This raises a compilation error though, and I don't know why because the code seems to...

No implicit format for MyClass available using Json.format

json,scala,playframework-2.0,implicit
I'm getting an error when using a complex object as attribute of another object on Json.format. I have two classes: RoleDTO and EmailInvitationDTO. EmailInvitationDTO has a RoleDTO. So, I declared: case class RoleDTO(id:Option[Long] = None, roleType:Int, userID:Long, fromHousingUnitID:Option[Long] = None, isAdmin:Option[Boolean] = None, fromResidentUserID:Option[Long] = None, documentNumber:Option[String] = None, fromCondoID:Option[Long]...

Loading an arbitrary file in the Play Framework 2 (Scala)

angularjs,scala,playframework,playframework-2.0,static-files
I'm trying to serve an AngularJS application using the Play 2 Framework for Scala and I think I understand, in general, how the routes and the templates work. In order to serve the angularJS files (which should NOT be available for users publicly), I'm currently placing them under /public and...

unable to convert scala map to json with play 2

json,scala,playframework-2.0
i have a case class signup with an optional variable "secondaryEmail" case class SignUp(firstNname : String, var lastName: String, var email: String, var secondryEmail : Option[String] ) i want to convert it to Json for that i have written a function to convert it into a Map def putInMap(obj: SignUp)...

Implicit conversion not taking place for Play Framework Lang in controller

scala,playframework,playframework-2.0
I have a view that takes in an implicit Lang, needed for Play's Messages object. The signature of this view is: @()(implicit lang: Lang) Then I have a controller that needs to create the view: def createView = Action { request => Ok(views.html.showView()) } And then I have an implicit...

Scala Play Forms verify that one date occurs after another

scala,playframework-2.0,playframework-2.3
My form has two dates, but I want to validate that the second date occurs after the first date. Is there a concise way to do this using Play's Form verification? Here is the form I am working with: val policyForm: Form[PolicyForm] = Form(mapping( "amount" -> of[Double].verifying("You need to enter...

How to tell why Play 2.4 is shutting down

logging,playframework-2.0,akka
I have Play 2.4 app that I'm currently running in development mode that I would like to move to production. The one hitch is that every other day or so of running, it just shuts down with no reason given. The message in the logs: 2015-05-14 03:06:11 -0600 [INFO] from...

Play Action Async wrapping a Future

scala,asynchronous,playframework-2.0
Let's say I have an Action Async block as below in one of my controller: def myCntr = Action.async { implicit request => // Step 1. .... // look up over the network // Step 2. .... // do a database call } What would it mean to wrap Step...

Unexpected exception in Play with Scala

scala,playframework-2.0,sbt
I am having an Unexpected exception in my Play2 application with Scala. The same error as mentioned in this question This is what I get in a browser: scala.MatchError: java.lang.StackOverflowError (of class java.lang.StackOverflowError) play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44) play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44) scala.Option.map(Option.scala:145) play.PlayReload$.taskFailureHandler(PlayReload.scala:44) play.PlayReload$.compileFailure(PlayReload.scala:40)...

Ebean many to many relationship with join fails

java,playframework-2.0,ebean
I'm having Some Gins and I'm having some Tonics that is a many to many relation. Now I'm also having a table gin2tonic. That just has 2 keys that both foreign to the id's from tonic and gin. I want to retrieve all Gins with the matching tonics. My db...

How to keep Akka running all the time in Play 2.3

playframework,playframework-2.0,akka
I am using akka as a scheduler in a website written with Play framework 2.3. I kept the server running by using activator run in dev environment. And when I changed some files and tried to visit my website, the Play server will compile these changed files and reload the...

Play Framework For Scala: Compilation error[type Application is not a member of package controllers]

scala,playframework,playframework-2.0
I try to compile a scala example in the book: "Play for Scala" but get a following compilation error on Play console: C:\Play\exp\ch6_implicits>activator run [info] Loading project definition from C:\Play\exp\ch6_implicits\project [info] Set current project to ch6_implicits (in build file:/C:/Play/exp/ch6_implicits/) --- (Running the application, auto-reloading is enabled) --- [info] p.a.l.c.ActorSystemProvider -...

Play framework and gradle

java,gradle,playframework-2.0
I would like to build the play framework with Gradle in a multiproject build. The play application would be one of my gradle subprojects. The controllers in play, will call methods in my other gradle projects. Gradle uses sbt by default. Should I just use sbt command line calls in...

Scala + Play + Intellij IDEA Issue

scala,intellij-idea,playframework-2.0,typesafe-activator,typesafe-stack
I was getting below error when I was making new Scala + Play project using activator. I am using standard activator method to generate Intellij Idea support for project but every time I was facing below issue. I dont know how to resolve below issue. Please help, # The project...

Configure Play framework messages to not format numbers

java,playframework-2.0
In the Play Framework, you can define files that have a key=value list of text. For instance myerror.number=The number {0} is not a double Which I can then get using: Messages.get("myerror.number", 5); And it will say: The number 5 is not a double When going above 1000 though, the output...

Why we need implicit Application

scala,playframework-2.0
I am creating an application using Play Framework and Scala and that application using implicit play.api.Application why we need this application in our scope? Thanks in advance...