wood burning stoves*
The moose likes Struts and the fly likes Presentation of the Validation Warnings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Presentation of the Validation Warnings" Watch "Presentation of the Validation Warnings" New topic
Author

Presentation of the Validation Warnings

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I would like to customize the validation warnings. And I want the warnings to be in; say, red color.

For example, I have a property that cannot be left blank; therefore, I have the following in the validation.xml:

And in the application.properties file, I have:


I got '???en_US.message.type??? is required.' in the browser window. '???en_US.message.type??? is required.' is not what I expect to see. How do I fix the problem?
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Check this post for how to fix the ???en_US.message.type??? problem.

Is the key "message.type" present in your resources file?

To get red warnings, you could place your <html:errors /> within a tag that has a styled class or do something like
<font color="red"><html:errors /></font>. Basically html and css stuff.
Alternately, you could use errors.header property in your message resources file to add color (i.e. use html tags in the value part of the property).

Sheldon Fernandes

[ September 24, 2004: Message edited by: Sheldon Fernandes ]
[ September 24, 2004: Message edited by: Sheldon Fernandes ]
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Now, the '???en_US.message.type???' problem is gone.

But, "the first time" that the form is displayed (a blank form), all the validation warning messages are on the top of the web page.

Can anybody tell what went wrong? Because validation warning messages are supposed to be shown "after" the form is submitted (if there are errors).

In addition, there is no <br> in between all my validation warning messages. I mean, all my validation warning messages are lined up in the same line. How do I show those messages line by line?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

But, "the first time" that the form is displayed (a blank form), all the validation warning messages are on the top of the web page.

This is usually caused by one of two things:
1) You are accessing the page by its submission action.
2) You are using a setup action and forgot to set its validation to false.

In addition, there is no <br> in between all my validation warning messages. I mean, all my validation warning messages are lined up in the same line. How do I show those messages line by line?

There are 4 ApplicationResources keys you can use for formatting:


A good workman is known by his tools.
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Now, every single validation warning messages shows up in a new line. Thanks for your advice.

But, I do not quite understand:

1) You are accessing the page by its submission action.
2) You are using a setup action and forgot to set its validation to false.

the action mapping in the struts-config.xml looks like:

The path /MailMessage leads to the "first time" presentation of a blank form. And the path /message/SendMessage invokes an action (by clicking on the Submit button of the form). It does the form validation before the form is submitted.

Why the validation warning messages show up on the top at the first time presentation of the blank form?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

validate defaults to true in ActionMappings. Since you did not specify the validate attribute for path="/MailMessage", it is running validation when all you mean to do is enter the page.
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Things are working as expected now. Thank you for your help.
 
 
subject: Presentation of the Validation Warnings
 
Similar Threads
Struts Validation Problem
Struts validation issue: Cannot load a validator resource
validator plugin and validate() method needs to use together
Struts validator question
Error Message for Struts Validation