Announcement Announcement Module
Collapse
No announcement yet.
validation error messages Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • validation error messages

    Hi,

    In an implementation of Validator an Errors object is provided which you can use to register an error for a field of the command bean (using one of the 'reject*' methods).

    All of these methods require an 'errorCode' parameter, which is used to look up the relevant error message to display. This is obviously very useful when you have an internationalized application, and the error message will be displayed to the user. However, if the request parameter that is incorrect is set by client-side JavaScript (rather than by user data entry), I don't want to look up the error message in a resource bundle, because it doesn't need to be displayed to the user or internationalized - it will just be shown in the logs.

    I can't seem to figure out how to register an error for a field that Spring does not attempt to lookup in a resource bundle. I've tried both of these:

    Code:
    errors.rejectValue("month", "Month index must be between 1 and 12");
    
    errors.rejectValue("month", null, "Month index must be between 1 and 12");
    But in both cases it seems that Spring is trying to use "Month index...." as a key into a resource bundle, because I see the following exception in the logs:

    Code:
    javax.servlet.jsp.JspTagException: No message found under code 'Month index must be between 1 and 12' for locale 'en_US'.
            at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:184)
            at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
            at org.apache.jsp.WEB_002dINF.jsp.validationErrorsView_jsp._jspx_meth_spring_005fmessage_005f1(validationErrorsV
    iew_jsp.java:436)
            at org.apache.jsp.WEB_002dINF.jsp.validationErrorsView_jsp.access$11(validationErrorsView_jsp.java:422)
            at org.apache.jsp.WEB_002dINF.jsp.validationErrorsView_jsp$validationErrorsView_jspHelper.invoke5(validationErro
    rsView_jsp.java:552)
    Is there any way to just raise an error for a particular field with an appropriate message, and bypass the lookup in the resource bundle?

    Thanks in Advance,
    DM

  • #2
    Spring will always try to resolve a errorCode (which is always required) to a resource message. If it cannot find a message for that code the default is used.

    Find a way to figure out if it was set by javascript or not, if set by javascript makeup some code which isn't found in the resourcebundle so that the default message is logged.

    Comment


    • #3
      Sounds good - thanks very much!

      Comment

      Working...
      X