简体   繁体   中英

How to override OmniFaces default validation/conversion error messages?

I'm using some OminFaces (1.8.1) validators as for example,

<o:validateAllOrNone components="a b c d" showMessageFor="someComponent"/>

If at least one of the specified fields is left blank in which case it displays a default message like as shown below.

a, b, c, d: Please fill out all or none of those fields

I want to override such error messages in resource bundles especially to get a localized message.

Unlike JSF, no resource bundles are found in OmniFaces. Is this still possible to override this error message somehow?

You can use the message attribute for that.

<o:validateAllOrNone components="a b c d" showMessageFor="someComponent"
    message="#{i18n['some.bundle.key']}" />

where i18n is the <resource-bundle><var> of your resource bundle.

Indeed, the OmniFaces ValidateMultipleFields components do not support providing those messages via <message-bundle> without the need to declare the message attribute everytime.


Coincidentally, 3 days ago I've for the upcoming OmniFaces 2.0 committed several changes in those validators which should make it possible to override the default message via <message-bundle> when using the component type as key. So in case of <o:validateAllOrNone> which has a component type of "org.omnifaces.component.validator.ValidateAllOrNone" , you should be able to override it in the resource bundle as identified by <message-bundle> as follows:

org.omnifaces.component.validator.ValidateAllOrNone = {0} all or none!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM