这是我的formbean:-
here is my formbean:-
public class LoginFormBean { @NotEmpty private String userId; @NotEmpty private String password; public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getPassword() { return password; } public void setPassword(String pass) { this.password = pass; } }在我的message.properties文件中,我写:-
and in my message.properties file i write:-
NotEmpty={0} must not empty.它向我显示错误消息:userId must not empty.和password must not empty.
It shows me error message as: userId must not empty. and password must not empty.
但是我想将错误消息显示为User Id must not empty.或'Password must not empty.'
But i want to show error message as User Id must not empty. or 'Password must not empty.'
我知道我可以在formBean中使用@NotEmpty(message="User Id must not empty"),但是我希望像需要更改消息一样同步消息,这将减少开销. 我已经搜索了JSR文档,但没有找到任何东西可以随时将我的属性名称userId替换为User Id.请大家帮我,从两天后就陷入困境. 如果不可能,请告诉我,否则,请告诉我.
I know i can use @NotEmpty(message="User Id must not empty") in my formBean but i want synchronize message as if we need to change message, it will be less overhead. I have searched the JSR docs but not find any thing to replace my attribute name userId to User Id on fly. Please guys help me, stuck in it from two days. If it is not possible then tell me or if not then help me in something alternative.
谢谢 短发
推荐答案您可能已经修复了此问题,但是要在JSR 303 Formbeans上设置错误消息,您需要以以下格式将条目添加到属性文件中:
You've probably fixed this by now, but to set up error messages on JSR 303 formbeans you need to add entries to your property file in the following format:
<Constraint-Name>.<formbean-name>.<attribute-name>=My Message Text在您的情况下,将是:
NotEmpty.loginFormBean.userId=User Id must not empty NotEmpty.loginFormBean.password=Password must not empty其中loginFormBean是表单的名称,而不是类名.
where loginFormBean is the name of your form and not the class name.
更多推荐
Spring中的JSR 303 Bean验证
发布评论