• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom validation messages

 
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

what is the best way to include your own validation messages? I have found the Messages.prop file in the javax.faces jar which contains all the error messages. The messages returned are too robotic so I would like my own for the error checks I need. I'm using Netbeans and can't edit the prop file. Is there a way to include my own prop file that can override the default while still using the keys in the default file that I don't override myself? That sounded long winded so I hope you understand what I am saying I could extract the javax.faces jar and edit the file but I am not sure how to jar it up again without breaking it!

Thanks,
Alan

EDIT: got this working!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can add your own custom overrides to the stock JSF message templates. If memory serves, you designate a properties file in the faces-config.xml file.

You can also override both the "required" and "validation failed" messages on a per-control basis like so:


In this particular case, "messages" is a backing bean I presumably constructed from a message bundle.
 
Alan Smith
Ranch Hand
Posts: 185
Netbeans IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Yes, you can add your own custom overrides to the stock JSF message templates. If memory serves, you designate a properties file in the faces-config.xml file.

You can also override both the "required" and "validation failed" messages on a per-control basis like so:


In this particular case, "messages" is a backing bean I presumably constructed from a message bundle.



Hi Tim,

I copied the default Messages.properties file into my src directory and put it in a package called messages. In the faces-config file I specified it as a message bundle named messages.Messages and it worked. I find it strange though that a property file like this has to be contained in a java package as opposed under the optional JSF resources folder that you can put in WEB-INF. That resources folder is great for css and images.

ps. I didn't know about the validatorMessage attribute, that's handy.

Thanks
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alan Smith wrote: I find it strange though that a property file like this has to be contained in a java package as opposed under the optional JSF resources folder that you can put in WEB-INF.



You get more flexibility when properties can come from a property service class instead of solely from a fixed-format file. Plus, by placing resources in the classpath, even when they are fixed-format data files, you get the benefit of mechanisms that were created for more than just web environments.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic