playframework-2.1

Play 2.1 Json serialization for traits?

为君一笑 提交于 2019-11-29 04:03:49
问题 I have this: package models import play.api.libs.json._ import play.api.libs.functional.syntax._ object ModelWrites { implicit val tmoWrites= Json.writes[TestModelObject] implicit val ihWrites = Json.writes[IntHolder] } case class TestModelObject(s1:String, s2:String) case class IntHolder(i1:Int, i2:Int) trait HasInts { val ints: List[IntHolder] } When I do this: scala> val tmo = new TestModelObject("hello", "world") with HasInts { val ints = List(IntHolder(1,2), IntHolder(3,4)) } scala> Json

How to execute DDL only when tables don't exist?

扶醉桌前 提交于 2019-11-29 03:56:32
I'm using Slick 1.0 with Play Framework 2.1 and MySQL. I'd like to control the ddl table creation so that it only takes place if the tables don't exist. That is to say that the tables should only get created the first time I start play. How to do it in Slick? Since I like to control the creation of my tables individually and keep it DRY, I just tend to add a utility method to my apps: def createIfNotExists(tables: TableQuery[_ <: Table[_]]*)(implicit session: Session) { tables foreach {table => if(MTable.getTables(table.baseTableRow.tableName).list.isEmpty) table.ddl.create} } Then you can

How do I specify a config file with sbt 0.12.2 for sbt test?

和自甴很熟 提交于 2019-11-28 23:36:44
I have a Play! project with unit tests and I am trying to run tests on my staging environment using sbt. Before I upgraded to Play 2.1, when I was using Play 2.0.4 and sbt 0.11.3 I could do $ sbt -Dconfig.file=conf/staging.conf test . Now sbt test seems to use the default application.conf no matter what I specify for -Dconfig.file. sbt start -Dconfig.file=conf/staging.conf still works fine. Is this behavior a bug with sbt 0.12.2 or should I be specifying a config file for running tests in a different way? test is using forked jvm. Use javaOptions sbt setting to pass jvm options to it e.g.

play framework 2.1 - scheduling async tasks

…衆ロ難τιáo~ 提交于 2019-11-28 23:29:35
In play's 2.0.x doc you can see how to schedule asynchronous tasks: http://www.playframework.org/documentation/2.0.4/ScalaAkka Akka.system.scheduler.schedule(0 seconds, 30 minutes, testActor, "tick") How can you achieve the same thing withthe recently releades Play 2.1??? The whole akka API seems to have changed... I've checked: https://github.com/playframework/Play20/wiki/Highlights https://github.com/playframework/Play20/wiki/Migration and also http://doc.akka.io/docs/akka/2.1.0-RC1/project/migration-guide-2.0.x-2.1.x.html also asked here: https://groups.google.com/d/topic/play-framework

Scala to JSON in Play Framework 2.1

喜欢而已 提交于 2019-11-28 16:53:49
I'm trying to convert Scala to JSON in the 2.1RC Play Framework. I can do the following and get JSON: import play.api.libs.json._ val a1=Map("val1"->"a", "val2"->"b") Json.toJSon(a1) Because a1 is just Map[String,String] that works OK. But if I have something more complex like where I have Map[String,Object], that doesn't work: val a = Map("val1" -> "xxx", "val2"-> List("a", "b", "c")) Json.toJSon(a1) >>> error: No Json deserializer found for type scala.collection.immutable.Map[String,Object] I found that I can do something like the following: val a2 = Map("val1" -> Json.toJson("a"), "val2" ->

Play Framework - Using Javascript Variable in Scala Template

江枫思渺然 提交于 2019-11-28 10:12:48
So I have something that looks like this: <script> $(document).ready(function(){ $("button.fadeMeOut").click(function(){ var fadeID = $(this).attr('id'); window.location.href = '@routes.Application.function(fadeID)'; }); }); </script> Of course this code will give a not found: value fadeID error. Is there a way for me to do something like this in Play Scala template? You can insert the relative URL in place of '@routes.Application....etc' So for example "/function/" + fadeID If the route of @routes.Application.function is /function biesior You can not mix Scala variables (server-side) with JS

Call Solr asynchronous from Play Framework

穿精又带淫゛_ 提交于 2019-11-28 05:44:53
问题 I have created a Play 2.1 Scala application. I am uncertain what's the best way to call Solr from a Play application: There is no Solr module for Play 2. AFAIK all Solr-APIs like SolrJ are blocking. I could wrap a SolrJ call into a Future , but this will also block a thread, correct? Should I use the play.api.libs.ws.WS library to call Solr and use Plays JSON support to extract the result (like in the example below) or is there any easier/faster way? val solrQuery: Future[play.api.libs.ws

play framework 2.1 junit test not working from eclipse

懵懂的女人 提交于 2019-11-28 02:44:27
问题 im following the zentask tutorial and wrote a junit test, the test wont run from the eclipse IDE its giving the following exception javax.persistence.PersistenceException: java.lang.IllegalStateException: Class [class play.db.ebean.Model] is enhanced and [class models.User] is not - (you can not mix!!) at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setEntityBeanClass(BeanDescriptorManager.java:1475) at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode

How to use prepared statement in JPA

我怕爱的太早我们不能终老 提交于 2019-11-28 00:03:08
问题 I am a play framework application Developer.I am using createNativeQuery method in JPA. In this example i want to use prepared statement. Please anyone help me? Here is the code without JPA. I need help to convert it to Prepared statement. Query query = JPA.em().createNativeQuery("select count(*) from truck t inner join" + "box b where t.truck_id=b.truck_id and t.shipment_upc='" + code + "'"); BigInteger val = (BigInteger)query.getSingleResult(); System.out.println(val); 回答1: Query query =

scala.concurrent.Future wrapper for java.util.concurrent.Future

末鹿安然 提交于 2019-11-27 22:46:23
I'm using Play Framework 2.1.1 with an external java library that produces a java.util.concurrent.Future result. I'm using the scala future's as opposed to Akka which I think is the right thing to do as of Play 2.1. How can I wrap the java.util.concurrent.Future up into a scala.concurrent.Future while still keeping the code non-blocking? def geConnection() : Connection = { // blocking with get connectionPool.getConnectionAsync().get(30000, TimeUnit.MILLISECONDS) } The above code returns a connection but uses a get so it becomes blocking def getConnectionFuture() : Future[Connection] = { future