为不同的复合组件指定不同的错误消息
有没有办法为不同类型的复合组件提供 REQUIRED 消息?
我希望能够在消息包中说出如下内容
javax.faces.component.UIInput.REQUIRED=Please enter a value for {0}
com.anon.sandbox.jsf.component.NameField.REQUIRED=ENTER A {} OR DIE
com.anon.sandbox.jsf.component.EmailField.REQUIRED=You forgot to enter a {0} address
,我可以通过为每种输入字段实现自定义验证器来做到这一点,但考虑到我想要自定义的唯一行为是错误消息,这似乎有点矫枉过正。
Is there a way to have REQUIRED messages for different kinds of composite components?
I'd like to be able to say something like the following in a message bundle
javax.faces.component.UIInput.REQUIRED=Please enter a value for {0}
com.anon.sandbox.jsf.component.NameField.REQUIRED=ENTER A {} OR DIE
com.anon.sandbox.jsf.component.EmailField.REQUIRED=You forgot to enter a {0} address
I could do this by implementing custom validators for each kind of input field, but given that the only behaviour I want to customise is the error message this seems like overkill.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
requiredMessage
属性来指定它们。对于您不知道的情况,
#{cc.resourceBundleMap}
引用复合组件特定资源包,该资源包由具有相同文件名的.properties
文件标识作为同一文件夹中的复合组件。因此,假设您有一个复合组件文件
foo.xhtml
,那么您可以在foo.properties
中指定本地化消息(因此foo_en.properties< /code>、
foo_es.properties
等)位于同一文件夹中。然后,这些本地化消息可通过上述#{cc.resourceBundleMap}
获得。Use the
requiredMessage
attribute to specify them.For the case you didn't knew that, the
#{cc.resourceBundleMap}
refers the composite component specific resource bundle which is identified by a.properties
file with the same filename as the composite component in the same folder.So, imagine that you've a composite component file
foo.xhtml
, then you can specify the localized messages infoo.properties
(and consequentlyfoo_en.properties
,foo_es.properties
, etc) which reside in the very same folder. Those localized messages are then available by the aforementioned#{cc.resourceBundleMap}
.