JSF:如何在验证消息中不显示元素ID? [英] JSF: How to not show the element id in validation messages?
问题描述
我有一个简单的JSF表单,对输入文本进行了一些验证.像这样:
I have a simple JSF form with some validation on the input text. Something like:
<h:inputText id="firstName" value="#{userHandler.user.firstName} required="true" />
<h:message for="firstName" />
工作正常.除了错误消息看起来像这样:
Works fine. Except that the error message looks like this:
"j_id786643870_20c27c0a:firstName:验证错误:该值为必填."
"j_id786643870_20c27c0a:firstName: Validation Error: Value is required."
如何告诉JSF不要显示元素的元素ID,而只显示文本消息?
How do I tell JSF not to show the element id of the element and just show the text message?
也就是说,我只想说:
验证错误:必填."
推荐答案
可以通过指定label
属性来覆盖它:
Either override it by specifying the label
attribute:
<h:inputText label="First name" />
或提供您自己的验证消息,并在faces-config.xml
的<message-bundle>
条目中指定它.消息密钥是在JSF规范中指定的.
Or supply your own validation messages and specify it in <message-bundle>
entry in faces-config.xml
. Message keys are specified in JSF specification.
- JSF validation - can this be simplified?
- How to create new messages properties to add adequate error messages?
这篇关于JSF:如何在验证消息中不显示元素ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!