Results 1 to 6 of 6

Thread: I18 and Validator

  1. #1

    Default 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.

  2. #2
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    To show errors in a javascript alert, put the following at the end of your page:

    Code:
    <spring&#58;hasBindErrors name="reoDataModel">
    	<script language="javascript">
    		errors='You have <c&#58;out value="$&#123;errors.errorCount&#125;" /> errors&#58;\n';
    		errors+='<c&#58;forEach var="error" items="$&#123;errors.allErrors&#125;">\n';
    		errors+='-<c&#58;out value="$&#123;error.defaultMessage&#125;" /></c&#58;forEach>';
    		alert&#40;errors&#41;;
    	</script>
    </spring&#58;hasBindErrors>
    cheers,

    Uze

  3. #3

    Default

    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.

  4. #4
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    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&#58;message code="$&#123;error.code&#125;" />
    ...and add errors like this:

    Code:
    errors.rejectValue&#40;"title", "someRessourceBundleErrorCode","Title can not be empty"&#41;;

    That should make it!

    Uze

  5. #5

    Default

    Hi uze,

    that's i wasn't so far, but without your help....

    Your help solve my pb, thanks a lot :-)

    Fabien.

  6. #6

    Default

    I was wondering if something like this was possible:

    messages.properties:

    Code:
    error.required=&#123;0&#125; is required
    label.loginName=Login Name
    controller/validator:

    Code:
    errors.rejectValue&#40;"loginName","required", new Object&#91;&#93;&#123;"label.loginName"&#125;, "Some Default"&#41;;
    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&#40;&#41;.getMessage&#40;"error.required", new Object&#91;&#93;&#123;getMessageSourceAccessor&#40;&#41;.getMessage&#40;"label.loginName"&#41;&#125;&#41;;
    Thanks for any help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •