playframework-2.2

Deadbolt: show parts of template only for current logged user

巧了我就是萌 提交于 2019-12-08 12:56:38
问题 In my system every user has an own public profile. I want to show an "Edit" button only on the profile page of the current logged user. Now I'm doing this by using this code @subjectPresent() { @if(userProfile == userLogged){ <button>Edit</button> } } where userProfile is the owner user of the current page, and userLogged is the actual logged user. Considering that I will have to do this check a lot of times, is there in Deadbolt or Scala a better (cleaner) way to do it? 回答1: As David

Handling a POST request in Play Framework 2.2.x with Java?

ⅰ亾dé卋堺 提交于 2019-12-08 12:46:26
问题 I'm getting started with Play 2.2.x, I'm trying to handle a POST requests, it's my understanding that I don't need to specify parameters in the conf/routes file but extract the queries using play's DynamicForm class, as below: import play.*; import play.api.data.Form; import play.data.DynamicForm; import play.mvc.*; import views.html.*; public static Result hello() { DynamicForm requestData = Form.form().bindFromRequest(); String firstname = requestData.get("firstname"); String lastname =

Test HTTP response with PlayFramework/JUnit

随声附和 提交于 2019-12-08 03:36:26
问题 I've been looking for hours to find a way to test if a route is correct with play. I mean, for exemple Is the GET request to localhost:9000/test actually return 200 OK ? I was not able to find any working example. 回答1: I use Play's WS (Web Services) library to achieve this. For Example: package endpoints; import com.fasterxml.jackson.databind.JsonNode; import models.Meh; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import play.libs.Json; import play.libs

Json Coast to Coast Play framework : Serializing Joda DateTime

半世苍凉 提交于 2019-12-07 19:30:18
问题 Hi all I am new to play framework, if someone knows of a better approach then mentioned below please let me know. So I have a model and Reads/Writes/Format for it case class Schedule (startDate: DateTime, endDate: DateTime) object ScheduleSerializers { val userDateFormatter = "dd/MM/yyyy HH:mm:ss" val nonImplicitUserFormatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss") implicit val jodaDateTimeReads = Reads.jodaDateReads(userDateFormatter) implicit val jodaDateTimeWrites = Writes

Play war deployment prevents Tomcat from stopping

家住魔仙堡 提交于 2019-12-07 19:30:08
问题 I am currently experiencing some onStop issues with my play application under Tomcat. I am using play 2.2.2, sbt 0.13.0, scala 2.10.4 and Tomcat 7 and jdk1.6. To create a war file I am using the play2war plugin(1.2) with: Play2WarKeys.servletVersion := "2.5" So deploying and running the application as well as Tomcat itself is running without any issues. But as soon as I try to stop the server with the default shutdown.sh I get SEVERE: The web application [/WEBSERVICE] appears to have started

when I run the play framework example with sbt some error

…衆ロ難τιáo~ 提交于 2019-12-07 14:20:32
问题 My operating system is Windows 8 , I downloaded the Play framework 2.2 without activator. I tried to build it by sbt. When I am under the zentask directory: I run sbt and the error is: C:\testprojects\zentasks>sbt last [error] java.lang.NullPointerException [error] Use 'last' for the full log. Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? last java.lang.NullPointerException at sbt.StringUtilities$.nonEmpty(StringUtilities.scala:12) at sbt.impl.GroupArtifactID.$percent

DdlGenerator constructor needs no arguments?

安稳与你 提交于 2019-12-07 14:18:16
问题 I wanted to unit test my database operation and I found this code. However, I get the followin error: [CityGame] $ test [info] Compiling 2 Java sources to /Users/pmichna/Documents/code/citygame/target/scala-2.10/test-classes... [error] /Users/pmichna/Documents/code/citygame/test/models/BaseModelTest.java:31: error: constructor DdlGenerator in class DdlGenerator cannot be applied to given types; [error] ddl = new DdlGenerator((SpiEbeanServer) server, new MySqlPlatform(), config); [error] ^

PlayFramework how to access routes in view from other submodule view

不羁的心 提交于 2019-12-07 08:49:22
I am writting application in Play Framework using submodules: common shopping ctd I would like to have in my view link to view from other module. /modules/common/app/views/choose.scala.html: @main() { <a href="@controllers.common.routes.Index.index">common module</a> <a href="@controllers.shopping.routes.Index.index">shopping module</a> } That code gives me an error: Compilation error object shopping is not a member of package controllers <a href="@controllers.shopping.routes.Index.index"> Please help me. How can I make this code compile correctly? My main routes file: # Include sub projects -

Create a generic Json serialization function

£可爱£侵袭症+ 提交于 2019-12-07 05:52:11
问题 Is it possible to create a generic function in Scala, using Play Framework 2.2, that will serialize an arbitrary object to JSON, without having to be supplied a writer or formatter? For instance, this non-generic code will create a JSON response given a Customer: import play.api.libs.json._ import play.api.libs.functional.syntax._ case class Customer(id: Int, name: String) object scratch { val p = Customer(1, "n") //> p : Customer = Customer(1,n) def createJsonResponseCustomer(data: Customer)

Play Framework 2: Best way of validating individual model fields separately

梦想的初衷 提交于 2019-12-07 04:13:43
问题 For this example, lets assume the user would like to update just the first name of his online profile. Form: <form data-ng-submit="updateFirstName()"> <label for="firstName">First name<label> <input type="text" name="title" data-ng-model="firstName"> <button type="submit">Update first name</button> </form> Controller: public class UsersController { public static Result updateFirstName() { Form<User> filledForm = Form.form(User.class).bindFromRequest(); // TODO: Validate firstName // if