JSF 2.0 validateRegex 带有自己的验证器消息
我有一个与此类似的代码:
<h:inputText id="email" value="#{managePasswordBean.forgotPasswordEmail}"
validatorMessage="#{validate['constraints.email.notValidMessage']}"
requiredMessage="#{validate['constraints.email.emptyMessage']}"
validator="#{managePasswordBean.validateForgotPasswordEmail}"
required="true">
<f:validateRegex pattern="^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$" />
</h:inputText>
支持 bean 中的验证器生成了自己的验证消息。但它被 inputText 标签的 validatorMessage 覆盖。
我的问题是:如何为 validateRegex 标记定义自定义验证器消息?我不想删除 validatorMessage 因为 JSF 会显示一条自己的错误消息,其中包含正则表达式模式等 ->我觉得不太漂亮。
感谢您的帮助:)
i am having a code similar to this:
<h:inputText id="email" value="#{managePasswordBean.forgotPasswordEmail}"
validatorMessage="#{validate['constraints.email.notValidMessage']}"
requiredMessage="#{validate['constraints.email.emptyMessage']}"
validator="#{managePasswordBean.validateForgotPasswordEmail}"
required="true">
<f:validateRegex pattern="^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$" />
</h:inputText>
The validator in the backing bean has its own validation message generated. but it is overwritten by the validatorMessage of the inputText tag.
My Question is: how can i define a custom validator message for the validateRegex tag? I don't want to remove the validatorMessage cause then JSF is displaying an own error message containing the regex pattern and so on -> which i dont find very pretty.
Thanks for the help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法为每个单独的验证器定义单独的
validatorMessage
。您能做的最好的事情就是在自定义验证器中进行正则表达式验证,以便您可以删除validatorMessage
。更新:自版本 1.3 起,< /code>
JSF 实用程序库的组件 OmniFaces 允许您设置基于每个验证器的验证器消息。然后,您的具体情况可以按如下方式解决:
与具体问题无关:如今,只要您仍然根据以下内容验证电子邮件地址,您就没有准备好统治世界拉丁字符。另请参阅 在 JSF 2 中使用正则表达式进行电子邮件验证/ PrimeFaces。
You can't define a separate
validatorMessage
for each individual validator. Best what you can do is to do the regex validation in your custom validator as well, so that you can remove thevalidatorMessage
.Update: since version 1.3, the
<o:validator>
component of the JSF utility library OmniFaces allows you to set the validator message on a per-validator basis. Your particular case can then be solved as follows:Unrelated to the concrete problem: these days you would be not ready for world domination as long as you still validate email addresses based on Latin characters. See also Email validation using regular expression in JSF 2 / PrimeFaces.
这对我有用。
您可以在“validatorMessage”中编写自定义消息
This worked for me.
You can write your custom messages in "validatorMessage"