playframework

Duplicate columns when using EmbeddedId with a ManyToOne mapping with Ebean

耗尽温柔 提交于 2020-01-01 07:58:45
问题 I have a model called "EventCheckin" which has a ManyToOne mapping to an "Event" and a "User". The PrimaryKey of the "EventCheckin" table is the id of the user and the id of the event. I'm trying to represent this using an "EmbeddedId" in my EventCheckin model but when I attempt to save an EventCheckin it tries to put the user_id and event_id values into the table twice which obviously fails: Caused by: org.h2.jdbc.JdbcSQLException: Duplicate column name "USER_ID"; SQL statement: insert into

How to configure logging in Play Framework 2.0 for Junit tests

二次信任 提交于 2020-01-01 07:08:08
问题 While using Eclipse > Run as Junit Test or the play command line, only the errors are logged to the console. How to show warning, info, and debug messages generated during Junit tests ? app/controllers/Application.java package controllers; import play.*; import play.mvc.*; public class Application extends Controller { public static Result index() { Logger.trace("**** Logger.isTraceEnabled = " + Logger.isTraceEnabled()+ " *****"); Logger.debug("**** Logger.isDebugEnabled = " + Logger

Where is the proper place to escape quotes in Play Framework?

余生颓废 提交于 2020-01-01 07:02:33
问题 I have the following flow: A user is presented with a form. He fills in the form fields, and submits to the controller, which persists this to the DB On another page, the Controller gets this record from the DB, and passes it to the view The view captures it as a javascript variable: var foo = '${user.bar}'; Now, if the user enters this string in the form: I have a quote - ' - very dangerous then the quote is passed through all the way to the DB and back, and results in a corrupt javascript

Handling exceptions in Play framework

风格不统一 提交于 2020-01-01 06:16:05
问题 I'm using play framework (2.3.x) for building a restful API. Today I have a try/catch block surrounding all my api functions in the API controller, to be able to catch the exceptions and return a generic "error json" object. Example: def someApiFuntion() = Action { implicit request => try { // Do some magic Ok(magicResult) } catch { case e: Exception => InternalServerError(Json.obj("code" -> INTERNAL_ERROR, "message" -> "Server error")) } } My question is: is it necessary to have a try/catch

Playframework with CSRF : “CSRF token not found in session”?

非 Y 不嫁゛ 提交于 2020-01-01 04:54:11
问题 I'm making a simple authentication system using Playframework with their built-in CSRF filter and Security.Authenticator system, but I'm facing a problem : When the user fill his login/password and submit enter, I have the following error : CSRF token not found in session I checked my form and the CSRF token is really present and correctly placed (inside the tag) Here is my routes : GET /login controllers.Authentication.login POST /login controllers.Authentication.authenticate And my

play framework logback custom layout

馋奶兔 提交于 2020-01-01 04:19:26
问题 I am trying to use a custom layout class for play framework 2.0 logback logging. First, I defined a custom layout class in package utils: package utils; public class MonitorLayoutForLogback extends LayoutBase<ILoggingEvent> { ... } In my conf/logging.xml file, I put: <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="utils.MonitorLayoutForLogback"> <param name="programName" value=

Where do I put startup code in Play Framework?

∥☆過路亽.° 提交于 2020-01-01 03:50:06
问题 I want to run some code on startup to pre-cache some stuff, and would also like to start a Timer to re-cache some things outside the critical path of a web request. Is this possible with Play Framework, and where so I put this code? 回答1: You need to create a bootstrap job which will be executed by Play at application start time. @OnApplicationStart public class Bootstrap extends Job { public void doJob() { //do stuff } } Read more about how to do this in the Play Manual. 回答2: For

How do I tell Play Framework 2 and Ebean to save null fields?

爱⌒轻易说出口 提交于 2020-01-01 02:39:11
问题 I'm using Play Framework 2 and Ebean. When a user submits a form to edit an existing object in the database, it doesn't save null values. I guess this is to prevent overwriting fields that aren't in the form with null. But how can I let them set fields in the form to null if they need to? For example, the user edits an Event object. Event.date is 1/1/13. The user sets the Event.date field in the form to empty and submits the form. Inspecting Event.date in the debugger shows its value is null.

Play2's anorm can't work on postgresql

北战南征 提交于 2020-01-01 01:44:06
问题 I found that the row parsers of play2's anorm depend on the meta data returned by jdbc driver. So in the built-in sample "zentasks" provided by play, I can find such code: object Project { val simple = { get[Pk[Long]]("project.id") ~ get[String]("project.folder") ~ get[String]("project.name") map { case id~folder~name => Project(id, folder, name) } } } Please notice that the fields all have a project. prefix. It works well on h2 database, but not on postgresql. If I use portgresql, I should

Adding Apache common dependency to Play Framework 2.0

情到浓时终转凉″ 提交于 2019-12-31 13:57:41
问题 i want to import org.apache.commons.io but i'm getting this error: [info] Compiling 1 Java source to /home/ghost/Bureau/app/play-2.0.1/waf/target/scala-2.9.1/classes... [error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:9: error: package org.apache.commons.io does not exist [error] import org.apache.commons.io.*; [error] ^ [error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:41: error: cannot find symbol [error] FileUtils.copyFile(file,