You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lukasz Lenart <lu...@apache.org> on 2025/05/06 08:55:38 UTC
Re: Validation problem
ś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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Dojo DateTimePicker
Posted by Lukasz Lenart <lu...@apache.org>.
wt., 6 maj 2025 o 21:22 shankar sawate <sa...@gmail.com> napisał(a):
> Do you have a new implementation of the Dojo DateTimePicker? If so, please
> share how to implement it, as the old one is deprecated
It's better to ask such a question in a new thread instead of mixing
it into a totally different topic.
The Struts DOJO plugin has been removed but you can always use the
DOJO framework directly in your page. There is a plenty of examples
how to do it
https://faraday.physics.utoronto.ca/test/dojo/demos/widget/datePicker.html
Cheers
Łukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validation problem
Posted by shankar sawate <sa...@gmail.com>.
Do you have a new implementation of the Dojo DateTimePicker? If so, please
share how to implement it, as the old one is deprecated
On Tue, 6 May, 2025, 2:27 pm Lukasz Lenart, <lu...@apache.org> wrote:
> ś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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Aw: Re: Validation problem
Posted by Ute Kaiser <ut...@web.de.INVALID>.
Hi,
escaping does not matter.
Output for
error.maxlength=\'{0}\' can not be greater than {1} characters.
is the same as for
error.maxlength='{0}' can not be greater than {1} characters.
(and the same as for error.maxlength={0} can not be greater than {1} characters.)
The '' always disappear.
I was looking for a solution because that worked in Struts1, and while migrating from Struts1 I wanted to keep the error messages the way my users are used to.
The links to the examples/mailreader2 do not use <message> with <param="0" "1" etc.> but thx. They work different, and maybe a help to redesign my error messages.
Best regards
Ute
> Gesendet: Dienstag, 6. Mai 2025 um 10:55
> Von: "Lukasz Lenart" <lu...@apache.org>
> An: "Struts Users Mailing List" <us...@struts.apache.org>
> Betreff: Re: Validation problem
>
>
> 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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org