如何自定义JSF验证错误消息 [英] How to customize JSF validation error message
本文介绍了如何自定义JSF验证错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何自定义验证失败时出现的验证消息?
How can I customize the validation message that appears when validation fails?
这是我的代码:
<h:form>
<p><h:inputText
id="userNo"
title="Type a number from 0 to 10:">
<f:validateLongRange
minimum="3"
maximum="6"/>
</h:inputText>
<h:commandButton id="submit" value="Submit"
action="response"/>
</p>
<h:message showSummary="true" showDetail="false"
id="errors1"
for="userNo"/>
</h:form>
当前消息看起来像这样:
Currently the message looks like this:
j_idt10:userNo: Validation Error: Specified attribute is not between the expected values of 3 and 6.
这不是特别用户友好.
Which is not particularly user-friendly.
推荐答案
最简单的方法是在<h:inputText>
标记中设置validatorMessage="my custom message"
属性.
The simplest way would be to set the validatorMessage="my custom message"
attribute in the <h:inputText>
tag.
有关更高级的方法,请阅读本文自定义验证错误消息在JSF 2.0中
For a more advanced way read this article Customize validation error message in JSF 2.0
以及这里是对您可以在JSF 2.0.x中覆盖的所有可用消息的完整引用.
这篇关于如何自定义JSF验证错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文