śr., 30 kwi 2025 o 19:47 Ute Kaiser <ut...@web.de.invalid> napisał(a): > > Hi, > I tried according to > https://struts.apache.org/core-developers/validation > Customizing validation messages > XML > > This is the example from above: > <field name="username"> > <field-validator type="requiredstring"> > <message key="errors.required"> > <param name="0">getText('username.field.name')</param> > </message> > </field-validator> > </field> > errors.required={0} is required. > username.field.name=Username > The final output will be as follow: > Username is required. > > Migrating from Struts1 to Struts7, this looked pretty familiar to me. > I tried > <field name="myObject.myField"> > <field-validator type="stringlength"> > <param name="maxLength">400</param> > <message key="error.maxlength"> > <param name="0">getText('myField.label')</param> > <param name="1">${maxLength}</param> > </message> > </field-validator> > </field> > error.maxlength='{0}' can not be greater than {1} characters. > myField.label=myExample > Output: > {0} can not be greater than null characters. > When I use > error.maxlength={0} can not be greater than {1} characters. (without the '' > which I want to use to emphasize the field name) > Output: > myExample can not be greater than null characters. > > I would like to have as output: > 'myExample' can not be greater than 400 characters.
Not sure if I understood your issue, did you try to use escape char? error.maxlength=\'{0}\' can not be greater than {1} characters. > The example from the struts page is for requiredstring. > Is there an example for stringlength with maxlenght-output? Take a look here https://github.com/apache/struts-examples/blob/main/mailreader2/src/main/resources/org/apache/struts/examples/mailreader2/Registration-Registration_save-validation.xml#L9-L14 and error message definition https://github.com/apache/struts-examples/blob/main/mailreader2/src/main/resources/org/apache/struts/examples/mailreader2/MailreaderSupport.properties#L94 there are also other examples, yet I'm not sure if they are up-to-date > And where can I find all possible field-validator types? Here is the list https://struts.apache.org/core-developers/validation#bundled-validators Cheers Łukasz --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org