尽管 JSF 中的某些验证器运行良好,但控制台上会出现一些错误消息或可能出现一些警告

发布于 2024-12-13 18:55:50 字数 2042 浏览 3 评论 0原文

在我的 JSF Web 应用程序中,一些验证器例如长度验证器 、正则表达式验证器 < /f:validateRegex> 和其他一些问题,在加载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-12-20 18:55:50

它只是告诉我们这些标签的 id 属性没有被处理。事实上,这些标签不支持 id 属性。将其删除。

<f:validateLength for="txtDemo" maximum="10" minimum="2"/>
<f:validateRegex for="txtDemo" pattern="[0-9]*" />

顺便说一句,for 属性在此构造中是不必要的。您也可以安全地将其删除。 for 属性仅适用于将验证器定位在复合组件内的输入上。

另请参阅:


与具体问题无关

元素已弃用从 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 an id attribute. Remove it.

<f:validateLength for="txtDemo" maximum="10" minimum="2"/>
<f:validateRegex for="txtDemo" pattern="[0-9]*" />

The for attribute is by the way unnecessary in this construct. You could also safely remove it. The for attribute applies only when targeting validators on inputs inside composite components.

See also:


Unrelated to the concrete problem, the <center> element is deprecated since HTML 4.01 in 1998. Remove it as well. Use CSS margin: 0 auto on the containing block element with a fixed width instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文