我在表单上定义自定义Constraint
时遇到问题。这是我的表格:
val form = Form(
mapping(
"field" -> boolean
)(MyForm.apply)(MyForm.unapply)
如果我执行以下操作:
val form = Form(
mapping(
"field" -> boolean
)(MyForm.apply)(MyForm.unapply).verifying("my constraint", f => f.field == true)
然后正常工作。但是,如果尝试使用以下自定义定义的Constraint
,则会引发空指针异常,并且我不知道为什么:
val form = Form(
mapping(
"field" -> boolean
)(MyForm.apply)(MyForm.unapply).verifying(myconstraint)
val myconstraint : Constraint[MyForm] = Constraint("myconstraint")({
form =>
if(form.field == true){
Valid
}else {
Invalid(Seq(ValidationError("problem")))
}
})
我尝试使用println
进行调试,但控制台上没有任何内容。
答案 0 :(得分:2)
尝试像这样将SELECT u.[FirstName] + ' ' + u.[LastName] AS EmployeeName,
CONVERT(DATE, e.loggedTime) as theday,
min(e.LoggedTime) as first
max(e.LoggedTime) as last
FROM [ProtegeGX].[dbo].[Users] u JOIN
[ProtegeGXEvents].[dbo].[Events] e
ON e.RecordIndex1 = u.UserID JOIN
[ProtegeGX].[dbo].[EventTypes] et
on e.EventTypeID = et.EventTypeID
WHERE e.LoggedTime Between '2019-05-29' AND '2019-05-31' AND
u.userid = 97
GROUP BY u.[FirstName] + ' ' + u.[LastName],
CONVERT(DATE, e.loggedTime);
定义移到myconstraint
定义之上
form
由于可能存在的前向引用问题,我们最终引用了一个未初始化的值。