Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4208

Allow customization of validation messages by passing arguments to the validator for the message

    XMLWordPrintableJSON

Details

    Description

      As of today the key/messages used by the annotated validators do not allow to receive custom arguments, since only the parameters defined by the annotation can be used. In order to improve that I suggest to add a parameter keyArgs to the validation annotations so it will be passed to the OGNL evaluator when it evaluates the key provided in the annotation. That way the following would be possible:

      @Validations(
              requiredStrings =
                  {@RequiredStringValidator(type = ValidatorType.SIMPLE,
                          fieldName = "event.email", key = "validation-error.mandatory")
                          keyArgs={"email","one","two"}
              }
      )
      

      Then the key/message could be something like this:

      validation-error.mandatory = The field ${getText(keyArgs[0])} is mandatory
      email= E-mail
      

      And the result would be

      The field E-mail is mandatory
      

      It would allow to customize the message even further than it allows now. I suppose it would need to be implemented also in xml validations, but I haven't used them, so I don't what would be needed for that.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jlmagc Jose L Martinez-Avial
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: