playframework-2.0

Reload app on custom file change in playframework

白昼怎懂夜的黑 提交于 2019-12-30 09:10:07
问题 In playframework there is auto-reload feature. It means that in development mode on each request play checks files on changes, and recompiles and reloads project if necessary. So, for example if I $ touch conf/routes , project will be reloaded on next request. I'd like to add some custom file to watch for. I believe watchSources setting contains list of files play is watching for. But it doesn't work for me. Consider, we want to add trigger file to watched sources. watchSources <+=

Retrieving port number in Play Framework 2 app

断了今生、忘了曾经 提交于 2019-12-30 06:32:08
问题 The question is: how do I retrieve the port number that play is listening on, no matter how it was defined (configuration, command line argument, or not at all). This answer Retrieving port number in-application using Play Framework must be for Play v1 because that code doesn't compile. In Play 2 Java there is: Integer port = Play.application().configuration().getInt("http.port"); That doesn't return the actual port number, at least not in all cases. If Play is run as: run 80 -Dhttp.address

Retrieving port number in Play Framework 2 app

隐身守侯 提交于 2019-12-30 06:32:03
问题 The question is: how do I retrieve the port number that play is listening on, no matter how it was defined (configuration, command line argument, or not at all). This answer Retrieving port number in-application using Play Framework must be for Play v1 because that code doesn't compile. In Play 2 Java there is: Integer port = Play.application().configuration().getInt("http.port"); That doesn't return the actual port number, at least not in all cases. If Play is run as: run 80 -Dhttp.address

play 2.0 creating a variable and assign values

这一生的挚爱 提交于 2019-12-30 05:24:05
问题 I searched a lot for this issue. I just want to create a variable in a scala html template and needed a temporary variable. The only solution I found and which makes "sense" is the following: @defining("hello text") {testvariable => <h1>output of variable: @testvariable</h1> } Is that really the only way? Are the guys from playframework serious? I don't want to pass a variable value from controller to the template. I just want to create a local simple variable and assign a value to it in an

Regenerate evolution scripts in play 2

这一生的挚爱 提交于 2019-12-29 00:08:11
问题 I am still developing first version of my application on play 2. How could I regenerate evolution scripts? 回答1: Disclaimer : it will destroy your existing database and create new one! The auto-evolution will auto-regenerate when: you are running your app in the dev mode in application.conf you have this line not commented : ebean.default="models.*" there is only one file in your evolutions folder and it's 1.sql it has this comment at the beginning: # --- Created by Ebean DDL 回答2: Using play 2

How to create custom INSERT INTO query in Ebean?

老子叫甜甜 提交于 2019-12-28 04:14:10
问题 I need to fill a table with large amount of data so I don't want to find related objects, but just put numeric values of them. For this I'd build a simple query ie: INSERT INTO article_category (article_id, category_id) VALUES (2,12); anyway can't find a way to do this with Ebean, I was trying: RawSql rawSql = RawSqlBuilder .parse("INSERT INTO article_category (article_id, category_id) VALUES (2,12)") .create(); however that throws an exception: [RuntimeException: Error parsing sql, can not

Language selector in Play 2.4 & Scala 2.11.6

此生再无相见时 提交于 2019-12-25 16:36:33
问题 I'm trying to implement this simple page with a language selector and a localized message: |...en...|▼| A message in english Ideally when the user changes the language the page should reload with an updated message and a different selected language |....fr....|▼| Un message en français but I can't get this to work: the page stays the same and the only thing that changes is the PLAY_LANG cookie. controller package controllers import javax.inject.Inject import play.api.mvc._ import play.api

How to use controller route defined by subcut in the template

自古美人都是妖i 提交于 2019-12-25 16:00:10
问题 I have a route defined as @com.xyx.abc(str: String) in my routes file. I want to use this route in a template. I tried using <a href="@com.xyx.abc("temp")/> Obviously didn't work. Thanks in advance. 回答1: Reverse routers are generated per package. So, if you have a package called com , a controller called xyx and a method called abc , then you can do this: @com.routes.xyx.abc("temp") Or if it's a more realistic @com.example.MyController.abc(str: String) , then it would be: @com.example.routes

Stub Controller in Play 2.0

♀尐吖头ヾ 提交于 2019-12-25 14:23:53
问题 I am trying folow the example from Mock Objects in Play[2.0] but unfortunately I am not having success. I have a UsersController that uses a UserModel. trait UserModel extends ModelCompanion[User, ObjectId] { // ... } Next, the abstract controller abstract class UsersController extends Controller { val userModel: UserModel def sayHello = Action(parse.json) { request => // return a play Action. Doesn't use userModel } // Other methods } In the routes file, I call method say Hello in this way:

Scala Play Framework image upload with Angular ng-file-upload

本秂侑毒 提交于 2019-12-25 09:14:38
问题 I am using Angular ng-file-upload (https://github.com/danialfarid/ng-file-upload) on the frontend to manage the file upload process. Unfortunately, form contains a complex object with multiple files. Using the MultipartFormData (https://www.playframework.com/documentation/2.5.x/ScalaBodyParsers) on the server side I have successfully decomposed the uploaded content and can read it from the request.body . Now, to my surprise, I do not have a simple Json Objects but rather a strangely formed