playframework-2.0

How do I run a comand line scala script that uses Play Framework app database?

可紊 提交于 2020-01-01 17:01:52
问题 I have this on my app/scripts folder (I created this folder inside app/ ). I'm not sure how I can properly set the classpath here, thus I didn't even run this to know if it will actually connect to the database. How can I run this in a clean way from the command line? package scripts import scala.collection.TraversableOnce import scala.collection.generic.SeqForwarder import scala.io.Source import scala.slick.jdbc.{StaticQuery => Q} import scala.slick.session.Session import scala.slick.session

Play 2.2 with Hibernate JPA and Postgres

爱⌒轻易说出口 提交于 2020-01-01 16:56:11
问题 I'm trying to get a Play 2.2 project to work with Hibernate JPA and a PostgreSQL database. I did it before with Play 2.1.1, where it worked perfectly. I get the following error now: play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: org/w3c/dom/ElementTraversal] at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:152) ~[play_2.10.jar:2.2.0] I have no idea where this comes from. My build.sbt looks like this:

Programmatically adding a route in Play2.0

浪子不回头ぞ 提交于 2020-01-01 09:17:27
问题 In play 1.2.X we could do Router.addRoute("GET", "/somePath", "controller.methodName"); I'm writing a module that adds a "route" that will be handled by a controller in the module. It's a OAuth handler and want to make it easy for users to not have to deal with the OAuth handshake etc. How can I do this in Play 2.0? 回答1: You can't add programmatically to the Routes object, but you can intercept web requests and handle them yourself by overriding GlobalSettings.onRouteRequest . For example:

How to use single quotes in i18n in Playframework2?

我怕爱的太早我们不能终老 提交于 2020-01-01 09:07:10
问题 While working on a French app (french language is full of single quotes), I needed to use i18n with single quotes and many other accentuated chars. So here is an extract of my messages.fr-FR file : some.key=C'est la vie! And here is the output : Cest la vie! How can I use strings containing single quotes in my messages? Already tried those : some.key=C\'est la vie! --> C\est la vie! some.key="C'est la vie!" --> "Cest la vie!" EDIT : Thanks to the link KDavid gave I was able to find the

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

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

How to use Evolutions in Play Framework 2.0?

强颜欢笑 提交于 2020-01-01 03:22:08
问题 For play 1.x, we can use play evolutions:apply , How can I do it in play-2.0-beta? 回答1: Evolution:apply is run automatically upon application start up. What is missing in Play 2.0-rc1 is a way to generate the evolutions scripts, and to manually apply them from the SBT console. But here is how to create them manually. Say you have the following definition in application.conf db.mydb.driver=org.h2.Driver db.mydb.url=jdbc:h2:mem:play Play2 will look for evolution in the following folder:

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