如何自定义 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>
目前消息是这样的:
j_idt10:userNo: Validation Error: Specified attribute is not between the expected values of 3 and 6.
这不是特别用户友好.
推荐答案
最简单的方法是在
标签.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屋!
查看全文