请注意:播放框架新手
说明:
我需要自定义验证消息,constraints.require完成了一些研究后,我发现使用了默认值:
@Constraints.Required
会显示error.required
通常位于conf/messages
[CompletionException: java.lang.IllegalStateException: Error(s) binding form: {"password":["This field is required"],"email":["This field is required"]}]
有关详细信息,请参阅this有用的SO帖子。
问题:
执行此操作时,我在网页上收到此错误:
[error] application -
! @7539mkaon - Internal server error, for (POST) [/User/Login] ->
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.IllegalStateException: Error(s) binding form: {"password":["This field is required"],"email":["This field is required"]}]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182)
at play.core.server.AkkaHttpServer$$anonfun$$nestedInanonfun$executeHandler$1$1.applyOrElse(AkkaHttpServer.scala:252)
at play.core.server.AkkaHttpServer$$anonfun$$nestedInanonfun$executeHandler$1$1.applyOrElse(AkkaHttpServer.scala:251)
at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:412)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at play.api.libs.streams.Execution$trampoline$.executeScheduled(Execution.scala:109)
at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:71)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68)
Caused by: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Error(s) binding form: {"password":["This field is required"],"email":["This field is required"]}
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at scala.concurrent.BatchingExecutor$Batch.processBatch$1(BatchingExecutor.scala:63)
Caused by: java.lang.IllegalStateException: Error(s) binding form: {"password":["This field is required"],"email":["This field is required"]}
at play.data.Form.get(Form.java:761)
at controllers.User.UserController.doLogin(UserController.java:85)
at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$10(Routes.scala:522)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:136)
at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:135)
at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:110)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:78)
at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31)
at play.core.j.JavaAction.$anonfun$apply$2(JavaAction.scala:113)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:653)
并在控制台输出中显示:
import play.data.validation.Constraints;
import javax.validation.constraints.Pattern;
public class UserLogin {
@Constraints.Required
@Pattern(regexp = ".+[@].+[.].+", message = "Please check your email address")
private String email;
@Constraints.Required
@Constraints.MinLength(message = "Minimum length is 8", value = 8)
@Pattern(regexp = "[\\d]{8,}]", message = "Please check your email address")
private String password;
@Constraints.Required
private Boolean bRememberMe;
public UserLogin(){}
public UserLogin(String email, String password, @Constraints.Required Boolean bRememberMe) {
this.email = email;
this.password = password;
this.bRememberMe = bRememberMe;
}
//...
}
模型UserLogin
conf/messages
我的error.required=This field is required
包含
@Constraints.Required
问题:
在评论isProcessed
时,此错误消失,导致此错误的原因是什么以及如何解决?