Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Presentation of the Validation Warnings

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Things are working as expected now. Thank you for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic