尽管 JSF 中的某些验证器运行良好,但控制台上会出现一些错误消息或可能出现一些警告
在我的 JSF Web 应用程序中,一些验证器例如长度验证器
、正则表达式验证器
和其他一些问题,在加载 JSF 页面时,即使它们运行良好且完全没有问题,也会发出一些错误,可能会发出警告。
这里不需要 JSF ManagedBean,并且以下代码中显示的提交按钮也没有任何关系,因为 Ajax 是在给定文本字段的 valueChange 事件上触发的。
以下是简单的 JSF 页面代码。
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Demo</title>
</h:head>
<h:body>
<h:form>
<center><br/><br/><br/>
<h:inputText id="txtDemo" required="true" requiredMessage="Mandatory."
validatorMessage="The field should contain al least 10 digits">
<f:validateLength id="lenValidator" for="txtDemo" maximum="10"
minimum="2"/>
<f:validateRegex pattern="[0-9]*" for="txtDemo" id="txtPattern"/>
<f:ajax id="txtAjax" event="valueChange" execute="txtDemo msg"
render="txtDemo msg"/>
</h:inputText><br/>
<h:message id="msg" for="txtDemo" showDetail="true" style="color:red"/>
<br/>
<h:commandButton id="btnSubmit" value="Submit"/>
</center>
</h:form>
</h:body>
在上面的代码中,虽然验证器
和
是如果运行良好,长度验证器不允许少于 2 个和大于 10 个字符,并且正则表达式验证器确保该字段应仅包含数字,当此 JSF 页面时,控制台上会显示红色消息是负载。显示的消息如下。
SEVERE: /Restricted/TempTags.xhtml @12,93 id="lenValidator" Unhandled by MetaTagHandler for type javax.faces.validator.LengthValidator
SEVERE: /Restricted/TempTags.xhtml @13,82 id="txtPattern" Unhandled by MetaTagHandler for type javax.faces.validator.RegexValidator
如果这些消息运行良好且没有问题,为什么会显示这些消息?
In my web application in JSF, some validators such as a length validator <f:validateLength></f:validateLength>
, a regular expression validator <f:validateRegex></f:validateRegex>
and some other issue some error possibly a warning even if they are functioning well with no problem at all, when the JSF page is loaded.
The JSF ManagedBean is unnecessary here and the submit button presented in the following code has nothing to do with, since Ajax is fired on the valueChange event of the text field given.
Following is the simple JSF page code.
<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Demo</title>
</h:head>
<h:body>
<h:form>
<center><br/><br/><br/>
<h:inputText id="txtDemo" required="true" requiredMessage="Mandatory."
validatorMessage="The field should contain al least 10 digits">
<f:validateLength id="lenValidator" for="txtDemo" maximum="10"
minimum="2"/>
<f:validateRegex pattern="[0-9]*" for="txtDemo" id="txtPattern"/>
<f:ajax id="txtAjax" event="valueChange" execute="txtDemo msg"
render="txtDemo msg"/>
</h:inputText><br/>
<h:message id="msg" for="txtDemo" showDetail="true" style="color:red"/>
<br/>
<h:commandButton id="btnSubmit" value="Submit"/>
</center>
</h:form>
</h:body>
In the above code, although the validators <f:validateLength></f:validateLength>
and <f:validateRegex></f:validateRegex>
are functioning well, the length validator does not allow less than 2 and greater than 10 characters and the regular expression validator ensures that the field should contain only digits, red colored messages appear on the console, when this JSF page is load. The messages displayed are as follows.
SEVERE: /Restricted/TempTags.xhtml @12,93 id="lenValidator" Unhandled by MetaTagHandler for type javax.faces.validator.LengthValidator
SEVERE: /Restricted/TempTags.xhtml @13,82 id="txtPattern" Unhandled by MetaTagHandler for type javax.faces.validator.RegexValidator
Why are these messages displayed, event if they are functioning well with no problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只是告诉我们这些标签的 id 属性没有被处理。事实上,这些标签不支持
id
属性。将其删除。顺便说一句,
for
属性在此构造中是不必要的。您也可以安全地将其删除。for
属性仅适用于将验证器定位在复合组件内的输入上。另请参阅:
< f:validateLength>
标签文档< f:validataRegex>
标签文档与具体问题无关,
元素已弃用从 1998 年的 HTML 4.01 开始。也将其删除。在具有固定宽度的包含块元素上使用 CSS
margin: 0 auto
。It's just telling that the
id
attribute of those tags is not been handled. Indeed, those tags do not support anid
attribute. Remove it.The
for
attribute is by the way unnecessary in this construct. You could also safely remove it. Thefor
attribute applies only when targeting validators on inputs inside composite components.See also:
<f:validateLength>
tag documentation<f:validataRegex>
tag documentationUnrelated to the concrete problem, the
<center>
element is deprecated since HTML 4.01 in 1998. Remove it as well. Use CSSmargin: 0 auto
on the containing block element with a fixed width instead.