playframework-2.0

How to replace a JSON value in Play

最后都变了- 提交于 2019-12-18 12:53:16
问题 How do I replace a value in a JSON value in Play? Code to illustrate: def newReport() = Action(parse.json) { request => var json = request.body if((json \ "customerId").as[Int] == -1){ // replace customerId after some logic to find the new value } json.validate[Report](Reports.readsWithoutUser).map { case _: Report => 回答1: According to the Play Documentation, JsObjects have a method ++ that will merge two JsObjects. So, when you have your new integer value, you simply need: val updatedJson =

How to contribute modules in Play Framework 2.0?

▼魔方 西西 提交于 2019-12-18 12:49:15
问题 The original Play Framework 1.x had an elegant and simple module management system. Coupled with the Play repository, it was a great way to quickly enhance an application with third party components & libraries. With Play 2.0, things are very different. How does one contribute the so called " modules "? 回答1: Quoting Guillaume Bort from the mailing list: modules are just standard subprojects. [...] now as everything is compiled, your module routes file must define its own route for controllers

Serving local images with Play 2 / Scala

亡梦爱人 提交于 2019-12-18 12:38:38
问题 I'm trying to figure out a pattern for uploading and serving files (images) locally. I figured out the upload part, but a little confused on the storage and serve part. I'm confused about how to display locally stored images on a single page using "Ok.sendFile". How do tie it into "img src" tags on the view? The other option I could think of is to run a (separate) web server locally just for storing files, which doesn't make much sense. 回答1: Just add an Action in a Controller that provides

How to improve compilation speed of Play Framework 2.0

此生再无相见时 提交于 2019-12-18 12:28:09
问题 Has someone already found some tweaks to improve the compilation speed of Play 2.0? I am currently using 2.0.1 java. 回答1: You can use play ~run . This compiles the files as soon as a change is deteced on the filesystem. Plus there are rumors about a big compilation boost coming in the next couple of months. (latter half of 2012) 回答2: I have written a very long post about how we have fix the compilation problem in Play Framework with my team. https://medium.com/@jfcote/the-ultimate-solution-to

Debug Playframework 2.0 in Eclipse

亡梦爱人 提交于 2019-12-18 12:28:06
问题 There's no eclipse folder in project folder after 'play eclipsify'. How to debug this project use eclipse with JPDA? 回答1: Since play 2.0, only thing need to do to debug a project is run project in console 'play debug run' and create a new debug conf of remote java application with port 9999 回答2: Exactly as fxp has said, in play 2.2.x you should do the following: Type in the play console play debug run In eclipse, right click over your project and go to Debug As, and then click on Debug

How to reverse generate an absolute URL from a route on Play 2 Java?

老子叫甜甜 提交于 2019-12-18 11:26:31
问题 I'd like to get the absolute URL from a controller in Play 2 Java. I found the exact same question for Scala, but I can't make it work in Java. public class MyController extends Controller { public static Result myMethod() { return ok(); } public static Result test() { Logger.info(routes.MyController.myMethod().url); // Doesn't work ! Logger.info(routes.MyController.myMethod().absoluteURL()); // Doesn't work ! Logger.info(routes.MyController.myMethod().absoluteURL(true)); // Doesn't work !

How to use generic class with specific objects in a static context?

折月煮酒 提交于 2019-12-18 10:56:09
问题 I'm gonna try to explain at my best. I use Play Framework 2, and I will do a lot of CRUD actions. Some of them will be identitcal, so I'd like to KISS and DRY so at first I was thinking about an abstract class containing the list , details , create , update and delete methods, with generic object, and extend this class by specifying which object to use (Model & Form) : public abstract class CrudController extends Controller { protected static Model.Finder<Long, Model> finder = null; protected

post method rendering 403 forbidden page instead of executing post method code

安稳与你 提交于 2019-12-18 08:57:20
问题 note: I am new to Play Framework Using this video tutorial and playlist, I manage to create a simple webapp. Problem: POST methods in routes file do not seem to execute the required POST code. Given the routes file below, browsing to localhost:{port}/user/register requests a GET , thus rendering and returning the register view . Filling in the register view fields, and clicking submit , refreshes the page (by clearing the input fields) and does show the expected "registered" text If method=

Play 2.0 Framework external Model in Template

无人久伴 提交于 2019-12-18 08:56:51
问题 Is it possible in Play 2.0, to make use of external model objects in a template? I can reference model objects from another jar in a Controller class. I don't know how to reference external model objects inside the Play 2.0 template files. 回答1: No problem. First, add the class to your classpath, either by adding the jar to the lib dir or through the "managed dependencies" in the projects/Build.scala. Make sure to have fully qualified name when declaring your model class in the template view

How to enforce strict serialization of JSON in Play 2.x

ぃ、小莉子 提交于 2019-12-18 08:35:03
问题 Play's JSON serialization is by default permissive when serializing from JSON into a case class. For example. case class Stuff(name: String, value: Option[Boolean]) implicit val stuffReads: Reads[Stuff] = ( ( __ \ 'name).read[String] and ( __ \ 'value).readNullable[Boolean] )(Stuff.apply _) If the following JSON was received: {name: "My Stuff", value: true, extraField: "this shouldn't be here"} It will succeed with a 'JsSuccess' and discard the 'extraField'. Is there a way to construct the