-
I18 and Validator
Hi,
today, i try the spring validator and i have 2 questions :
- is it possible to show errors in a javascript popup ?
- in the errors.rejectValue, can i use an i18n value like this :
("field", "errors.minlength", new Object[]{"i18n field name","2"},"");
instead of :
("field", "errors.minlength", new Object[]{"field name","2"},"");
Thanks,
Fabien.
-
To show errors in a javascript alert, put the following at the end of your page:
Code:
<spring:hasBindErrors name="reoDataModel">
<script language="javascript">
errors='You have <c:out value="${errors.errorCount}" /> errors:\n';
errors+='<c:forEach var="error" items="${errors.allErrors}">\n';
errors+='-<c:out value="${error.defaultMessage}" /></c:forEach>';
alert(errors);
</script>
</spring:hasBindErrors>
cheers,
Uze
-
Hi uze,
Thanks for your reply, it works fine to show errors in a javascript popup.
Do you know how can i get a complet translated message (cause error.defaultMessage is not i18n) ?
I tried to replace "<c:out value="${error.defaultMessage}" />" with <fmt:message key="${error.code}"/> but it doesn't working with all kind of message ex : typeMismatch.java.util.Date, it only display "???typeMismatch???".
Thanks,
Fabien.
-
Fabien,
Tu y etait presque :wink: ! In fact, to do things the right way,you must use the <spring:message> tag instead of JSTL's. So try this in your JSP:
Code:
<spring:message code="${error.code}" />
...and add errors like this:
Code:
errors.rejectValue("title", "someRessourceBundleErrorCode","Title can not be empty");
That should make it!
Uze
-
Hi uze,
that's i wasn't so far, but without your help....
Your help solve my pb, thanks a lot :-)
Fabien.
-
I was wondering if something like this was possible:
messages.properties:
Code:
error.required={0} is required
label.loginName=Login Name
controller/validator:
Code:
errors.rejectValue("loginName","required", new Object[]{"label.loginName"}, "Some Default");
jsp:
???
If I want it to say "Login Name is required" when there is an error, how would I do that on the JSP? The <spring:message> tag has no where to pass in arguments. Do I have to resolve the message before putting it into the errors object using
Code:
getMessageSourceAccessor().getMessage("error.required", new Object[]{getMessageSourceAccessor().getMessage("label.loginName")});
Thanks for any help!