You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ute Kaiser <ut...@web.de.INVALID> on 2025/10/14 12:48:56 UTC
How to use ActionName-alias-validation.xml?
Hi,
I have a problem with a validation that should only be activated for method create in my Action.
I do not understand how to use this "Action Alias" in the documentation:
>>
https://struts.apache.org/core-developers/validation.html
Validation rules can be specified:
1.Per Action class: in a file named ActionName-validation.xml
2. Per Action alias: in a file named ActionName-alias-validation.xml
In this context, “Action Alias” refers to the action name as given in the Struts configuration. Often, the name attribute matches the method name, but they may also differ.
<<
I had some success with option one "ActionName-validation.xml" by creating X-validation.xml (X=Name of the java action class)
But I am lost trying the second option. X-create-validation.xml is ignored, X-validate-validation.xml is ignored.
It would be so nice if someone could just add the file name for the following example:
Migrating from Struts1 to Struts7, I have complex action names with slashes.
<action name="a/b/myaction.validate"
class="myPath.MyAction"
method="create">
<result name="input" type="tiles">mytiles</result>
<result name="success" type="tiles">mytiles</result>
</action>
Best regards
Ute
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Re: Re: How to use ActionName-alias-validation.xml?
Posted by Lukasz Lenart <lu...@apache.org>.
PR is ready
https://github.com/apache/struts-site/pull/278
pt., 17 paź 2025 o 10:55 Łukasz Lenart <lu...@gmail.com> napisał(a):
>
> pt., 17 paź 2025 o 10:34 Ute Kaiser <ut...@web.de.invalid> napisał(a):
> >
> > What a surprising answer :-)
> >
> > I tried, it worked and the filename is 120 characters...
> >
> > Some remarks on this solution:
> > - There is no documentation on this case with slashes in action names and the replacement "/" -> "-" resulting in "MyAction-a-b-myaction.validate-validation.xml"
>
> Yes, this is something discovered by CC, I mean there is a note but
> maybe unclear
>
> > - For my example below I may implement validateCreate() = validateMethodName. (I stumbled on this here: https://stackoverflow.com/questions/6763652/struts-validator-annotation-to-call-method.)
>
> This is documented here, but you are right it's hard to find it,
> especially when using annotations
> https://struts.apache.org/core-developers/default-workflow-interceptor
>
>
> Cheers
> Łukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Re: Re: How to use ActionName-alias-validation.xml?
Posted by Łukasz Lenart <lu...@gmail.com>.
pt., 17 paź 2025 o 10:34 Ute Kaiser <ut...@web.de.invalid> napisał(a):
>
> What a surprising answer :-)
>
> I tried, it worked and the filename is 120 characters...
>
> Some remarks on this solution:
> - There is no documentation on this case with slashes in action names and the replacement "/" -> "-" resulting in "MyAction-a-b-myaction.validate-validation.xml"
Yes, this is something discovered by CC, I mean there is a note but
maybe unclear
> - For my example below I may implement validateCreate() = validateMethodName. (I stumbled on this here: https://stackoverflow.com/questions/6763652/struts-validator-annotation-to-call-method.)
This is documented here, but you are right it's hard to find it,
especially when using annotations
https://struts.apache.org/core-developers/default-workflow-interceptor
Cheers
Łukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Aw: Re: Re: How to use ActionName-alias-validation.xml?
Posted by Ute Kaiser <ut...@web.de.INVALID>.
What a surprising answer :-)
I tried, it worked and the filename is 120 characters...
Some remarks on this solution:
- There is no documentation on this case with slashes in action names and the replacement "/" -> "-" resulting in "MyAction-a-b-myaction.validate-validation.xml"
- For my example below I may implement validateCreate() = validateMethodName. (I stumbled on this here: https://stackoverflow.com/questions/6763652/struts-validator-annotation-to-call-method.)
Maybe that is the reason why I experimented too long and in vain with MyAction-create-validation.
There are many ways to validate, but sometimes confusing :-)
Thx and best regards
Ute
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Re: How to use ActionName-alias-validation.xml?
Posted by Lukasz Lenart <lu...@apache.org>.
Full answer from CC:
⏺ 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="a/b/myaction.validate"
class="myPath.MyAction"
method="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}-validation.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 = 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="a/b/myaction.validate"
class="myPath.MyAction"
method="create">
<result name="input" type="tiles">mytiles</result>
<result name="success" type="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
Łukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Re: How to use ActionName-alias-validation.xml?
Posted by Ute Kaiser <ut...@web.de.INVALID>.
Hi,
yes I enabled support for slashes in action names. (right at migration start :-)
no namespaces; I wasted some effort but too many side effects in the application to be migrated.
What would be the right xml filename for the example below?
Then I would try again.
Kind regards and all the best for the next Struts7 release
Ute
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to use ActionName-alias-validation.xml?
Posted by Lukasz Lenart <lu...@apache.org>.
wt., 14 paź 2025 o 14:50 Ute Kaiser <ut...@web.de.invalid> napisał(a):
> Migrating from Struts1 to Struts7, I have complex action names with slashes.
> <action name="a/b/myaction.validate"
> class="myPath.MyAction"
> method="create">
> <result name="input" type="tiles">mytiles</result>
> <result name="success" type="tiles">mytiles</result>
> </action>
Did you enable support for slashes in action names?
<constant name="struts.enable.SlashesInActionNames" value="true"/>
https://struts.apache.org/core-developers/action-configuration#action-names
And it's better to use namespaces in such case
Cheers
Łukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org