我正在尝试使用 Extjs4 将我的类字段与我的视图字段绑定。我已经做到了可以提交表单并返回结果的程度,但不确定如果验证失败,如何在各个字段旁边显示任何错误消息。我想将这些字段直接绑定到我的类(就像我们为 spring mvc 所做的那样 - bindingResults.rejectValue("currentPassword", "currentPassword.incorrect", "Password is wrong"); 它会显示在视图中)。
我的表单面板:
{
xtype : 'formpanel',
url: 'changePassword',
id : 'changePasswordForm',
method: 'POST',
success: function(){},
items : [{
xtype : 'fieldset',
id : 'passwordChange',
title : 'Change Password',
iconCls : 'user',
items : [{
xtype : 'passwordfield',
label : 'Current Password',
name : 'currentPassword',
id : 'currentPassword',
}, {
xtype : 'passwordfield',
label : 'New Password'
name : 'newPassword1',
id : 'newPassword1',
}, {
xtype : 'passwordfield',
label : 'Repeat Password',
name : 'newPassword2',
id : 'newPassword2',
},]
} ]
},{
xtype : 'button',
id: 'changePassword',
}
在按钮单击时执行提交事件的控制器 -
this.getChangePasswordForm().submit();
我的课是
@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
public @ResponseBody String changePasswordInSettings(ChangePasswordForm changePasswordForm) {
User currentUser = User.find();
String enteredPSHash = HashUtil
.generateHash(changePasswordForm.getCurrentPassword(),
currentUser.getEmail());
String existingPSHash = currentUser.getPassword();
if(!enteredPSHash.equals(existingPSHash)) {
//bindingResults.rejectValue("currentPassword",
//"currentPassword.incorrect", "Password is incorrect");
}
if (!changePasswordForm.getNewPassword1().equals(changePasswordForm.getNewPassword2())) {
//bindingResults.rejectValue("newPassword2",
// "newPassword2.dontMatch", "Passwords dont match");
}
//if (!bindingResults.hasErrors()) {
String newPSHash = HashUtil.generateHash(changePasswordForm.getNewPassword1(),currentUser.getEmail());
currentUser.setPassword(newPSHash);
//model.addAttribute("successful", new Boolean(true)); //}
return "success";
}
如何在我的视图中显示错误消息?