Re: Re: How to use ActionName-alias-validation.xml?

Lukasz Lenart <[email protected]> Fri, 17 Oct 2025 08:17:32 +0200
Newsgroups gmane.comp.jakarta.struts.user
Message-ID <CAMopvkO-7m7KttKZ8SAGrJjTLXv00rdbb2ehKK1Yh4QxdYmFSg@mail.gmail.com>
Full answer from CC:

=E2=8F=BA Based on my search of the Struts codebase, I found exactly how
action aliases with slashes are handled!

  Answer for Your Specific Case

  For your action configuration:
  <action name=3D"a/b/myaction.validate"
          class=3D"myPath.MyAction"
          method=3D"create">

  The validation file name should be:
  MyAction-a-b-myaction.validate-validation.xml

  File location: Place it in src/main/resources/myPath/ (following
your package structure)

  The Key Rule

  When using action aliases (the name attribute), slashes are replaced
with hyphens in the validation file name:

  Pattern: ClassName-{action-name-with-slashes-replaced-by-hyphens}-validat=
ion.xml

  How It Works

  The validation file resolution code in
AnnotationActionValidatorManager.java:68-71 shows:

  protected List<ValidatorConfig> buildAliasValidatorConfigs(Class
aClass, String context, boolean checkFile) {
      String fileName =3D aClass.getName().replace('.', '/') + "-" +
context.replace('/', '-') + VALIDATION_CONFIG_SUFFIX;
      return loadFile(fileName, aClass, checkFile);
  }

  Notice: context.replace('/', '-') - this converts
a/b/myaction.validate to a-b-myaction.validate

  Complete Example

  For clarity, your full setup should be:

  struts.xml:
  <action name=3D"a/b/myaction.validate"
          class=3D"myPath.MyAction"
          method=3D"create">
      <result name=3D"input" type=3D"tiles">mytiles</result>
      <result name=3D"success" type=3D"tiles">mytiles</result>
  </action>

  Validation files:
  - For all methods: src/main/resources/myPath/MyAction-validation.xml
  - For this specific alias:
src/main/resources/myPath/MyAction-a-b-myaction.validate-validation.xml

  The alias-specific validation will only apply when the action is
invoked via the a/b/myaction.validate URL pattern.


Cheers
=C5=81ukasz