我可以在控制台中打印错误消息,但无法在UI中显示错误消息。
这是行动代码:
public static void welcome(User user){
validation.required("User Name",user.name).message("validation.message.em");
validation.required("Password",user.password).message("validation.message.em");
if(validation.hasErrors()) {
System.out.println("Validation errors found!!!");
for(Error error:validation.errors())
System.out.println(error.message());
params.flash(); // add http parameters to the flash scope
validation.keep(); // keep the errors for the next request
login();
}
这是UI html代码:
#{form @Application.welcome(), method:'get', id:'loginForm' }
<table>
<tr style="height: 100px">
<td colspan="2"><h1>
<b>Login</b>
</h1></td>
</tr>
<tr>
#{field 'user.name'}
<td> &{field.name} </td>
<td><input type="text" id="${field.id}" name="${field.name}" value="${field.value}" class="${field.errorClass}">
<span class="error">${field.error}</span>
#{/field}
</tr>
<tr>
#{field 'user.password'}
<td> &{field.name} </td>
<td><input type="password" id="${field.id}" name="${field.name}" value="${field.value}" class="${field.errorClass}">
<span class="error">${field.error}</span>
#{/field}
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Login"></td>
</tr>
</table>
#{/form}
这是消息conf条目:
user.name=User Name
user.password=Password
validation.message.em=%s is required.
请让我知道我错过了什么:(
谢谢,
答案 0 :(得分:1)
将代码更改为;
validation.required("user.name",user.name).message("validation.message.em");
validation.required("user.password",user.password).message("validation.message.em");