playframework-2.2

Date formatting with locale in Play Framework 2.2

别等时光非礼了梦想. 提交于 2019-12-05 18:23:38
From what I can see in the auto-generated application.conf file, dates/times in Play Framework 2.2 are formatted according to the definition of date.format in that file. I have, for instance, defined date.format=yyyy-MM-dd date.format.dk=d. MMMM yyyy These values, however, seem to be ignored by the framework when printing dates in Scala templates. This thread gives a solution where one enters the pattern directly into the template as myDate.format("yyyy-MM-dd") . (If using Jodatime I guess this becomes myDate.toDate().format("yyyy-MM-dd") since there is no format() defined on the DateTime

Using POST routes parameters in Play Framework

痴心易碎 提交于 2019-12-05 17:28:48
问题 I have a login route that should transmit its input parameters as POST variables. I have defined my route like this: POST /v1/accounts/login controllers.v1.Accounts.login(username: String, password: String) and my Controller is like this: object Accounts extends Controller { def login(username: String, password: String) = Action { Ok("Foo " + username) } } When I test this route using Chromes Advance REST Client it only works for GET parameters and not if I send it as application/x-www-form

Enable CORS in Java Play Framework 2.2.x

*爱你&永不变心* 提交于 2019-12-05 16:25:14
问题 I am having trouble of enabling cross domain in Java Play 2.2.x In Java Play 2.1.3 this code works by putting it in Global.java public class Global extends GlobalSettings { private class ActionWrapper extends Action.Simple { public ActionWrapper(Action action) { this.delegate = action; } @Override public Result call(Http.Context ctx) throws java.lang.Throwable { Result result = this.delegate.call(ctx); Http.Response response = ctx.response(); response.setHeader("Access-Control-Allow-Origin",

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

我怕爱的太早我们不能终老 提交于 2019-12-05 09:29:49
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 hasErrors() return bad request with errors as json // else save and return ok() } } Model: @Entity public

Play Framework: Redirect to controller method with arguments

六月ゝ 毕业季﹏ 提交于 2019-12-05 07:14:52
I am building a web application with PLAY framework 2.2.1 and am trying to display all available http get query parameters for the requested site in the address bar, even the ones that are not set in the request. In cases where not all http get parameters are set, I want to add the unset parameters with the default values and make a redirect. I have a site that can be requested with GET: GET /test controllers.Application.test(q:String, w:String ?= null, f:String ?= null, o:String ?= null) Here is the method that I'd like to have in controllers.Application : public static Result test(String q,

Cannot register class in Ebean server (Play Framework 2 - Java)

自闭症网瘾萝莉.ら 提交于 2019-12-05 04:22:50
I am getting the following error when running my Play Framework 2.2.x (Java) project: Configuration error Cannot register class [models.SomeClass] in Ebean server The error messages displayed in the browser points me to the line ebean.default="models.*" in my application.conf , and the console tells me that I have a java.lang.VerifyError: Bad type on operand stack in one of my methods. There is nothing special about the methods for which this happens, and it has happened for a handfull of methods now. I have found out that the error can be avoided by using a static method instead: that is by

How do I describe a bridge table to Ebean?

血红的双手。 提交于 2019-12-05 03:46:28
Lets say I have these tables: ORDER: id ITEM: id ORDER_ITEM: order_id, item_id The table: ORDER_ITEM is a bridge table between ORDER and ITEM . How do I describe this threesome to Ebean ? I would prefer not to use raw SQL so that I can still create and update these entities. UPDATE Sat Nov 9 02:32:40 UTC 2013 Ok, lets make this problem harder and more representative of my actual situation. The column names dont fit the convention: ORDER: order_number ITEM: item_number ORDER_ITEM: my_order, my_item You don't have to create special bridge table yourself unless you want to have other fields there

Play Framework Multi-Tenant Filter

依然范特西╮ 提交于 2019-12-05 03:24:30
问题 I'm attempting to build a multi-tenant application using Play Framework 2.2 and have run into a problem. I want to set a session key in the global onRouteRequest (or onRequest in Java) that identifies the site ID for the domain the user is requesting. In literally dozens of other frameworks this type of thing is painless (e.g. Django), but I'm learning that the session object in Play is apparently immutable, however. So, right now, I have something like this: override def onRouteRequest

How to print @ symbol in HTML with play framework (scala)

*爱你&永不变心* 提交于 2019-12-04 20:10:18
问题 I am new to Scala and play 2.1 and I come from a PHP background. I am not able to print the @ symbol in HTML. I am getting the following error: not found: value Hotmail Here is my code: myname<label>@Hotmail.com</label> Please let me know how I can print the @ symbol. Thanks in advance. 回答1: Double it: myname<label>@@Hotmail.com</label> It's called escape syntax. Other rules for play template framework can be found here 回答2: You can also write HTML Entity code &#64 for printing @ symbol in

compose slick dbaction with authenticated action

人走茶凉 提交于 2019-12-04 16:32:03
I have my custom authenticated action that is like def Authenticated(rights: String*) = new ActionBuilder[MyAuthenticatedRequest] { *** } In my controller I use this action to check the user has the right to view the page def password = Authenticated(UserRights.USER) { implicit request: MyAuthenticatedRequest[_] => Users.findById(request.account.id) match { case Some(user) => Ok(views.html.settings.password(frontUser, user)) case _ => NotFound } } My oject Users uses slick to retrieve the user in the database def findById(id: Long)(implicit s: Session): Option[User] = users.where(_.id === id)