playframework-2.5

how to add custom ValidationError in Json Reads in PlayFramework

放肆的年华 提交于 2021-02-08 05:35:10
问题 I am using play Reads validation helpers i want to show some custom message in case of json exception eg:length is minimum then specified or the given email is not valid , i knnow play displays the error message like this error.minLength but i want to display a reasonable message like please enter the character greater then 1 (or something ) here is my code case class DirectUserSignUpValidation(firstName: String, lastName: String, email: String, password: String) extends Serializable object

Migrating Play framework 2.4 chunked response to play 2.5/2.6 akka stream Source

﹥>﹥吖頭↗ 提交于 2020-01-25 08:13:33
问题 My goal is to migrate from java play 2.4 Chunked response to akka source. Essentially: public Result getDCcsv() { response().setHeader("Content-Type", "text/csv"); response().setHeader("Content-Disposition", "attachment;filename=users.csv"); response().setHeader("Cache-control", "private"); return ok(new Results.Chunks<String>() { public void onReady(Results.Chunks.Out<String> out) { //blocking calls to read data from DB in manageable chunks out.write(data) } }); } to public Result getDCcsv()

EhCache instance with name 'play' already exists

时光总嘲笑我的痴心妄想 提交于 2020-01-23 12:34:10
问题 I faced the issue with the Play framework default cache ( EHCache ) when working with asynchronous couchdatabase java driver. Play crashes on the hot reload with the error: Error in custom provider, play.api.cache.EhCacheExistsException: An EhCache instance with name 'play' already exists. I found this could be not only with the couchdatabase driver but also in some other scenarios, like https://groups.google.com/forum/#!topic/pac4j-dev/2_EUOCrov7M. 回答1: I figure out a solution - force cache

Render view while processing data

廉价感情. 提交于 2020-01-17 08:31:05
问题 I'm on Play Framework 2.5.14, with play for java. I have a Service that loads and processes some data, and it takes a long time to process that data. I'm doing it this way: Controller public Result showData() { List<Data> data = service.getProcessedData(); return ok(views.html.data.render(data)); } View @(data: List[Data]) <!-- html code --> But when I go to the page it is in blank a long time because service.getProcessData() takes too long. When the function finish, then the view is rendered

how to add alphanumeric field in play framework

ε祈祈猫儿з 提交于 2020-01-07 04:38:08
问题 i need to add alphanumeric field in play for that i am trying this code object TestValidation { implicit val readTestUser: Reads[TestValidation] = ( (JsPath \ "firstName").read(minLength[String](1)) and (JsPath \ "lastName").read(minLength[String](1)) and (JsPath \ "email").read(email) and (JsPath \ "password").read(minLength[String](1)))(TestValidation.apply _) i want the "password" field to be alphanumeric i have added this custom validation constraint now i want to intregate this during

Play 2.5 application requests hang

假装没事ソ 提交于 2020-01-06 16:25:53
问题 I'm running a small scala Play application in dev mode on a vagrant box using activator run. When accessing the app from the browser some of the requests hang for what looks like indefinitely. This seems to be the same issue as described in this question for play 2.0 Play Framework Hanging when hitting app in browser. The solution suggested there however doesn't seem to apply to the latest version of play. I'm not sure where to start investigating this issue. Any help will be appreciated! 回答1

ScalaWS in play framework 2.5 and dependency injection of WSClient in custom class

戏子无情 提交于 2020-01-06 03:07:52
问题 I'm using Scala Play framework 2.5 and I would like to use dependency injection to inject an instance of WSClient into my custom class but I keep getting the following error. not enough arguments for constructor TestClass: (ws: play.api.libs.ws.WSClient)service.TestClass. Unspecified value parameter ws. I get the error when running the following code class TestClass @Inject() (ws: WSClient) { def doSomething() : Future[WSResponse] = { ws.url("http://www.google.com").get() } } val test = new

Playframework: Type mismatch found scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result

强颜欢笑 提交于 2020-01-04 04:03:10
问题 I have the following code in my controller in PlayFramework: def auth = Action.async(parse.json) { request => { val authRequest = request.body.validate[AuthRequest] authRequest.fold( errors => Future(BadRequest), auth => { credentialsManager.checkEmailPassword(auth.email, auth.password).map { case Some(credential: Credentials) => { sessionManager.createSession(credential.authAccountId).map { //Throws an error case Some(authResponse: AuthResponse) => Ok(Json.toJson(authResponse)) case None =>

Play Framework 2.5.1 routing and dependency injection (for Java)

邮差的信 提交于 2020-01-03 13:40:33
问题 I have this in my "routes" file: POST /accounts/ controllers.AccountsController.createOneAccount And in my AccoutsController.java: package controllers; import com.google.inject.Inject; import play.Application; import play.mvc.Controller; import play.mvc.Result; import services.AccountService; import java.io.IOException; public class AccountsController extends Controller { @Inject private Application application; final String host = application.configuration().getString("db.default.host");

Play Framework 2.5.1 routing and dependency injection (for Java)

孤人 提交于 2020-01-03 13:40:16
问题 I have this in my "routes" file: POST /accounts/ controllers.AccountsController.createOneAccount And in my AccoutsController.java: package controllers; import com.google.inject.Inject; import play.Application; import play.mvc.Controller; import play.mvc.Result; import services.AccountService; import java.io.IOException; public class AccountsController extends Controller { @Inject private Application application; final String host = application.configuration().getString("db.default.host");