[英]retrieve error message values from .properties file
i need to retrieve error message values for client side validation from messages.properties file and display it on a page. 我需要从messages.properties文件中检索用于客户端验证的错误消息值,并将其显示在页面上。 i used
<fmt:message key="uname.prop" />
. 我使用
<fmt:message key="uname.prop" />
。
<script type="text/javascript">
$(document).ready(function() {
$("#userRegistrationDetails").validate({
rules: {
username: "required",
email: {
required : true,
email : true
},
password: "required",
confpass: {
required :true,
equalTo: "#password"
}
},
messages: {
username: <fmt:message key="uname.prop" />,
email: "Please enter valid email address",
password: "Please enter the password",
confpass: "Please enter the same password"
}
});
});
in my form page. 在我的表单页面中。
i cannot use label attribute since it is not defined in spring. 我不能使用label属性,因为它没有在spring中定义。
From what I understand of the question, similar to how you have defined the message for username, why not do the same for email and other field? 根据我对该问题的理解,类似于您为用户名定义消息的方式,为什么不对电子邮件和其他字段执行相同操作?
messages: {
username: <fmt:message key="uname.prop" />,
email: "<fmt:message key="error.invalid.email"/>",
password: "<fmt:message key="error.required.password"/>",
...
}
If you need to get quoted string, you should surround it with quotes: 如果需要获取带引号的字符串,则应将其用引号引起来:
username: "<spring:message code = 'uname.prop' javaScriptEscape = 'true' />",
Also note that since you are generating Javascript source, you need to apply the appropriate escaping. 另请注意,由于您要生成Javascript源,因此需要应用适当的转义。 Javascript escaping is supported by
<spring:message>
, so it makes sense to use it rather than <fmt:message>
. <spring:message>
支持Javascript转义,因此使用它而不是<fmt:message>
是有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.