Hello Till,

I write my impementation of errors tag, which uses some additional
data to form error messages on more flexible manner. I think it can be
useful for you.
Struts' errors tag now prints all messages from one errors heap. But
with add method in ActionErrors class source of error can be specified
(source, field name - as you prefer). Error messages for each source
can be retrieved separately. ActionErrors can not be used for it -
there is not method to retrieve sources list and messages for source.
I extend ActionErrors with this methods to ActionErrorsExt and write
special tag ErrorsExt to use this new feature. This tag takes source
name, tries to retrieve message from resource bundle using source name
as key. And after that prints separately messages for each source with
source name as title.
I can send it for you.

P.S. But you can patch your code in one line and solve your
     problem without my tag... 8))

   if ((subtitle == null) || (subtitle.length() == 0)) {
     errors.add("subtitle", new ActionError("error.required",
>        messages.getMessage("news.subtitle")));
   }

     Change quoted string to
>        messages.getMessage(locale, "news.subtitle")));
     and set locale variable to you current locale from session.
   
Sunday, December 10, 2000, 8:38:40 PM, you wrote:

TN> I want to use localized messages to show validation errors. It would be no
TN> problem, if I write an error message for every field. But I have a lot of
TN> fields and a lot of different error messages.

TN> What I am trying to do is the following:

TN> NewsForm.validate() {
TN>   // ...
TN>   if ((subtitle == null) || (subtitle.length() == 0)) {
TN>     errors.add("subtitle", new ActionError("error.required",
TN>        messages.getMessage("news.subtitle")));
TN>   }
TN>   // ...
TN> }

TN> resources.properties
TN>   error.required={0} is required.
TN>   news.author=Author
TN>   news.subtitle=Subtitle

TN> resources_de.properties
TN>   error.required={0} ist erforderlich.
TN>   news.author=Autor
TN>   news.subtitle=Untertitel


TN> The result should be either "Subtitle is required" or "Untertitel ist
TN> erforderlich".
TN> But I get "Subtitle is required" and "Subtitle ist erforderlich" (attributes
TN> are always default locale). So how could I solve this problem?

TN> Any hints appreciated.

TN> Regards,
TN> Till






-- 
Best regards,
 Oleg                            mailto:[EMAIL PROTECTED]


Reply via email to