aspose file tools*
The moose likes JSF and the fly likes Custom validation messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom validation messages" Watch "Custom validation messages" New topic
Author

Custom validation messages

Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 162

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!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Alan Smith
Ranch Hand

Joined: Oct 19, 2011
Posts: 162

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

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom validation messages