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

Need some help customizing this error message

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

For the text fields on my JSF page that are required, I want to display a message ilke ...

ERROR! The "Name" field requires a value.

So I put an entry in my resources bundle that looks like ...



However, the actual message that gets dislpayed if someone doesn't enter a value on a text field is

ERROR! The "index:Name" field requires a value.

"index" is the id of the containing form. Any ideas how to get rid of the "index:" portion of the error message? Thanks, - Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a "requiredMessage" attribute that can be used to attach per-control messages instead of falling back on the generic system-generated format.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But isn't there a way I can define a single message in my resource bundle, yet somehow have customize it so that it reads

The field 'Subject' is required.

Instead of having 32 messages in my resource bundle for 32 fields? Please provide an example. Thanks, - Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Alvarado wrote:But isn't there a way I can define a single message in my resource bundle, yet somehow have customize it so that it reads

The field 'Subject' is required.

Instead of having 32 messages in my resource bundle for 32 fields? Please provide an example. Thanks, - Dave


Well, yes, actually, there is. You can put an attribute on the control to give it a display name to be used in the message in place of its system ID. However, since I'm too lazy to RTFM, I'll leave it to you.

Most of the time, I have the item messages displaying physically adjacent to their respective controls, so I just go with "*lt;- This item is REQUIRED" in red type. But you can do it your way as well.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion, but the erorr is still displaying incorrectly ...

ERROR! The "index:Name" field requires a value.

and I want to get rid of "index:" (the name of the form). I tried the attribute thing you suggested, but it didn't eliminate the problem ...



Here is what is in my resources bundle ...



If you can point me to a link or a term to search on Google, that would be awesome. I tried searching with the phrase from your thread, "an attribute on the control to give it a display name" but didn't get anything meaningful. Thanks, - Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic